chore: move all binding code to abi

This commit is contained in:
Nurul Huda (Apon) 2026-01-30 03:01:04 +06:00
parent 424b437a33
commit 81fcafa67f
No known key found for this signature in database
GPG key ID: 5D3F1DE2855A2F79
4 changed files with 56 additions and 69 deletions

View file

@ -27,15 +27,6 @@ pub const CalendarDisplay = enum {
always,
never,
critical,
fn toCApi(self: CalendarDisplay) abi.c.ShowCalendar {
return switch (self) {
.auto => .Auto,
.always => .Always,
.never => .Never,
.critical => .Critical,
};
}
};
pub const ToZonedDateTimeOptions = struct {

View file

@ -56,13 +56,6 @@ const FromOptions = struct {
const Overflow = enum {
constrain,
reject,
fn toCApi(self: Overflow) abi.c.ArithmeticOverflow {
return switch (self) {
.constrain => abi.c.ArithmeticOverflow_Constrain,
.reject => abi.c.ArithmeticOverflow_Reject,
};
}
};
const PartialDateTime = struct {
@ -144,7 +137,7 @@ const FromInit = union(enum) { plain_date: PlainDate, plain_date_time: PlainDate
pub fn from(info: anytype, opts: FromOptions) !PlainDateTime {
const T = @TypeOf(info);
const overflow = if (opts.overflow) |f| f.toCApi() else null;
const overflow = if (opts.overflow) |f| abi.to.toArithmeticOverflow(f) else null;
if (T == PlainDateTime) return info.clone();
if (T == PlainTime) return abi.c.temporal_rs_PlainDateTime_from_partial(.{ .time = info._inner }, abi.toArithmeticOverflowOption(overflow));
if (T == PlainDate) return abi.c.temporal_rs_PlainDateTime_from_partial(.{ .date = info._inner }, abi.toArithmeticOverflowOption(overflow));

View file

@ -28,8 +28,6 @@ pub const TimeZone = struct {
const tz = try abi.extractResult(result);
return .{ ._inner = tz };
}
// ...existing code...
};
pub const Disambiguation = enum {
@ -37,8 +35,6 @@ pub const Disambiguation = enum {
earlier,
later,
reject,
// ...existing code...
};
pub const OffsetDisambiguation = enum {
@ -46,8 +42,6 @@ pub const OffsetDisambiguation = enum {
prefer_offset,
ignore_offset,
reject,
// ...existing code...
};
pub const CalendarDisplay = enum {
@ -55,23 +49,17 @@ pub const CalendarDisplay = enum {
always,
never,
critical,
// ...existing code...
};
pub const DisplayOffset = enum {
auto,
never,
// ...existing code...
};
pub const DisplayTimeZone = enum {
auto,
never,
critical,
// ...existing code...
};
pub const ToStringOptions = struct {

View file

@ -310,51 +310,66 @@ const dur = @import("Duration.zig");
const ins = @import("Instant.zig");
pub const to = struct {
pub fn toTimeZone(val: anytype) c.TimeZone {
return val._inner;
}
pub fn toArithmeticOverflow(val: anytype) c.ArithmeticOverflow {
return switch (val) {
.constrain => c.ArithmeticOverflow_Constrain,
.reject => c.ArithmeticOverflow_Reject,
};
}
pub fn toDisambiguation(d: anytype) c.Disambiguation {
return switch (d) {
.compatible => c.Disambiguation_Compatible,
.earlier => c.Disambiguation_Earlier,
.later => c.Disambiguation_Later,
.reject => c.Disambiguation_Reject,
};
}
pub fn toShowCalendar(val: anytype) c.ShowCalendar {
return switch (val) {
.auto => c.ShowCalendar_Auto,
.always => c.ShowCalendar_Always,
.never => c.ShowCalendar_Never,
.critical => c.ShowCalendar_Critical,
};
}
pub fn toTimeZone(val: anytype) c.TimeZone {
return val._inner;
}
pub fn toOffsetDisambiguation(o: anytype) c.OffsetDisambiguation {
return switch (o) {
.use_offset => c.OffsetDisambiguation_Use,
.prefer_offset => c.OffsetDisambiguation_Prefer,
.ignore_offset => c.OffsetDisambiguation_Ignore,
.reject => c.OffsetDisambiguation_Reject,
};
}
pub fn toDisambiguation(d: anytype) c.Disambiguation {
return switch (d) {
.compatible => c.Disambiguation_Compatible,
.earlier => c.Disambiguation_Earlier,
.later => c.Disambiguation_Later,
.reject => c.Disambiguation_Reject,
};
}
pub fn calendarDisplay(cd: anytype) c.DisplayCalendar {
return switch (cd) {
.auto => c.DisplayCalendar_Auto,
.always => c.DisplayCalendar_Always,
.never => c.DisplayCalendar_Never,
.critical => c.DisplayCalendar_Critical,
};
}
pub fn toOffsetDisambiguation(o: anytype) c.OffsetDisambiguation {
return switch (o) {
.use_offset => c.OffsetDisambiguation_Use,
.prefer_offset => c.OffsetDisambiguation_Prefer,
.ignore_offset => c.OffsetDisambiguation_Ignore,
.reject => c.OffsetDisambiguation_Reject,
};
}
pub fn displayOffset(o: anytype) c.DisplayOffset {
return switch (o) {
.auto => c.DisplayOffset_Auto,
.never => c.DisplayOffset_Never,
};
}
pub fn calendarDisplay(cd: anytype) c.DisplayCalendar {
return switch (cd) {
.auto => c.DisplayCalendar_Auto,
.always => c.DisplayCalendar_Always,
.never => c.DisplayCalendar_Never,
.critical => c.DisplayCalendar_Critical,
};
}
pub fn toDisplayTimeZone(val: anytype) c.DisplayTimeZone {
return switch (val) {
.auto => c.DisplayTimeZone_Auto,
.never => c.DisplayTimeZone_Never,
.critical => c.DisplayTimeZone_Critical,
};
}
pub fn displayOffset(o: anytype) c.DisplayOffset {
return switch (o) {
.auto => c.DisplayOffset_Auto,
.never => c.DisplayOffset_Never,
};
}
pub fn toDisplayTimeZone(val: anytype) c.DisplayTimeZone {
return switch (val) {
.auto => c.DisplayTimeZone_Auto,
.never => c.DisplayTimeZone_Never,
.critical => c.DisplayTimeZone_Critical,
};
}
pub fn unit(opt: ?t.Unit) ?c.Unit {
return if (opt) |u| @as(c.Unit, @intCast(to.unitToCApi(u))) else null;
}