This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Type Function
fnFe_(comptimebits: comptime_int) type {
returnstruct {
constSelf = @This();
constFeUint = Uint(bits);
/// The element value as a `Uint`.v: FeUint,
/// `true` if the element is in Montgomery form.montgomery: bool = false,
/// The maximum number of bytes required to encode a field element.pubconstencoded_bytes = FeUint.encoded_bytes;
// The number of active limbs to represent the field element.fnlimbs_count(self: Self) usize {
returnself.v.limbs_len;
}
/// Creates a field element from a primitive./// This function may not run in constant time.pubfnfromPrimitive(comptimeT: type, m: Modulus(bits), x: T) (OverflowError || FieldElementError)!Self {
comptimeassert(@bitSizeOf(T) <= bits); // Primitive type is larger than the modulus type.constv = tryFeUint.fromPrimitive(T, x);
varfe = Self{ .v = v };
trym.shrink(&fe);
trym.rejectNonCanonical(fe);
returnfe;
}
/// Converts the field element to a primitive./// This function may not run in constant time./// Returns an error if the element is in Montgomery form.pubfntoPrimitive(self: Self, comptimeT: type) (OverflowError || RepresentationError)!T {
if (self.montgomery) {
returnerror.UnexpectedRepresentation;
}
returnself.v.toPrimitive(T);
}
/// Creates a field element from a byte string.pubfnfromBytes(m: Modulus(bits), bytes: []constu8, comptimeendian: Endian) (OverflowError || FieldElementError)!Self {
constv = tryFeUint.fromBytes(bytes, endian);
varfe = Self{ .v = v };
trym.shrink(&fe);
trym.rejectNonCanonical(fe);
returnfe;
}
/// Converts the field element to a byte string./// Returns an error if the element is in Montgomery form.pubfntoBytes(self: Self, bytes: []u8, comptimeendian: Endian) (OverflowError || RepresentationError)!void {
if (self.montgomery) {
returnerror.UnexpectedRepresentation;
}
returnself.v.toBytes(bytes, endian);
}
/// Returns `true` if the field elements are equal, in constant time.pubfneql(x: Self, y: Self) bool {
returnx.v.eql(y.v);
}
/// Compares two field elements in constant time.pubfncompare(x: Self, y: Self) math.Order {
returnx.v.compare(y.v);
}
/// Returns `true` if the element is zero.pubfnisZero(self: Self) bool {
returnself.v.isZero();
}
/// Returns `true` is the element is odd.pubfnisOdd(self: Self) bool {
returnself.v.isOdd();
}
};
}
A field element.