silk/numeric
Shared compile-time addition witness for generic algorithms over primitive integers.
When to use
Add an Integer bound when a generic function needs the + operator. Use the concrete integer
modules directly when an algorithm also needs width-specific conversion, overflow, bitwise, or
formatting operations.
Details
Witnesses are selected during specialization and create no Effect requirement, provider slot, or
runtime dispatch. The interface intentionally exposes only the operation spelled by +; it does
not attempt to erase the distinct ranges and conversion rules of each integer type.
Gotchas
The selected primitive operation keeps its ordinary overflow policy. Integer addition traps when the mathematical result is outside the selected type's range.
Examples
Add values through one generic contract
import silk.numeric as Numeric
pub fn main() -> i32 {
return Numeric.add<i32>(40, 2)
}Import as Integer with import silk.numeric.
Public declarations: 2.
Integer
pub interface IntegerStatic addition contract for primitive integer values.
When to use
Use this interface when a generic algorithm needs only ordinary integer addition.
Details
Interfaces select compiler-known operations during specialization. They do not create effect requirements, provider slots, or runtime dispatch.
Operation add
operator + fn add(left: Self, right: Self) -> SelfAdds two values and traps if the selected integer type cannot represent the result.
Implementation Integer for u8
impl Integer for u8Operation add
add = Intrinsic.u8AddImplementation Integer for u16
impl Integer for u16Operation add
add = Intrinsic.u16AddImplementation Integer for u32
impl Integer for u32Operation add
add = Intrinsic.u32AddImplementation Integer for u64
impl Integer for u64Operation add
add = Intrinsic.u64AddImplementation Integer for usize
impl Integer for usizeOperation add
add = Intrinsic.usizeAddImplementation Integer for i8
impl Integer for i8Operation add
add = Intrinsic.i8AddImplementation Integer for i16
impl Integer for i16Operation add
add = Intrinsic.i16AddImplementation Integer for i32
impl Integer for i32Operation add
add = Intrinsic.i32AddImplementation Integer for i64
impl Integer for i64Operation add
add = Intrinsic.i64AddImplementation Integer for isize
impl Integer for isizeOperation add
add = Intrinsic.isizeAddadd
pub fn add<T>(left: T, right: T) -> TAdds two values and traps if the selected integer type cannot represent the result.
When to use
Use this function to call ordinary integer addition from generic code.