chore: move all binding code to abi
This commit is contained in:
parent
4a4c63d2a5
commit
c3fd84984d
4 changed files with 56 additions and 69 deletions
|
|
@ -27,15 +27,6 @@ pub const CalendarDisplay = enum {
|
||||||
always,
|
always,
|
||||||
never,
|
never,
|
||||||
critical,
|
critical,
|
||||||
|
|
||||||
fn toCApi(self: CalendarDisplay) abi.c.ShowCalendar {
|
|
||||||
return switch (self) {
|
|
||||||
.auto => .Auto,
|
|
||||||
.always => .Always,
|
|
||||||
.never => .Never,
|
|
||||||
.critical => .Critical,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ToZonedDateTimeOptions = struct {
|
pub const ToZonedDateTimeOptions = struct {
|
||||||
|
|
|
||||||
|
|
@ -56,13 +56,6 @@ const FromOptions = struct {
|
||||||
const Overflow = enum {
|
const Overflow = enum {
|
||||||
constrain,
|
constrain,
|
||||||
reject,
|
reject,
|
||||||
|
|
||||||
fn toCApi(self: Overflow) abi.c.ArithmeticOverflow {
|
|
||||||
return switch (self) {
|
|
||||||
.constrain => abi.c.ArithmeticOverflow_Constrain,
|
|
||||||
.reject => abi.c.ArithmeticOverflow_Reject,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const PartialDateTime = struct {
|
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 {
|
pub fn from(info: anytype, opts: FromOptions) !PlainDateTime {
|
||||||
const T = @TypeOf(info);
|
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 == PlainDateTime) return info.clone();
|
||||||
if (T == PlainTime) return abi.c.temporal_rs_PlainDateTime_from_partial(.{ .time = info._inner }, abi.toArithmeticOverflowOption(overflow));
|
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));
|
if (T == PlainDate) return abi.c.temporal_rs_PlainDateTime_from_partial(.{ .date = info._inner }, abi.toArithmeticOverflowOption(overflow));
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,6 @@ pub const TimeZone = struct {
|
||||||
const tz = try abi.extractResult(result);
|
const tz = try abi.extractResult(result);
|
||||||
return .{ ._inner = tz };
|
return .{ ._inner = tz };
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...existing code...
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Disambiguation = enum {
|
pub const Disambiguation = enum {
|
||||||
|
|
@ -37,8 +35,6 @@ pub const Disambiguation = enum {
|
||||||
earlier,
|
earlier,
|
||||||
later,
|
later,
|
||||||
reject,
|
reject,
|
||||||
|
|
||||||
// ...existing code...
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const OffsetDisambiguation = enum {
|
pub const OffsetDisambiguation = enum {
|
||||||
|
|
@ -46,8 +42,6 @@ pub const OffsetDisambiguation = enum {
|
||||||
prefer_offset,
|
prefer_offset,
|
||||||
ignore_offset,
|
ignore_offset,
|
||||||
reject,
|
reject,
|
||||||
|
|
||||||
// ...existing code...
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const CalendarDisplay = enum {
|
pub const CalendarDisplay = enum {
|
||||||
|
|
@ -55,23 +49,17 @@ pub const CalendarDisplay = enum {
|
||||||
always,
|
always,
|
||||||
never,
|
never,
|
||||||
critical,
|
critical,
|
||||||
|
|
||||||
// ...existing code...
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const DisplayOffset = enum {
|
pub const DisplayOffset = enum {
|
||||||
auto,
|
auto,
|
||||||
never,
|
never,
|
||||||
|
|
||||||
// ...existing code...
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const DisplayTimeZone = enum {
|
pub const DisplayTimeZone = enum {
|
||||||
auto,
|
auto,
|
||||||
never,
|
never,
|
||||||
critical,
|
critical,
|
||||||
|
|
||||||
// ...existing code...
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ToStringOptions = struct {
|
pub const ToStringOptions = struct {
|
||||||
|
|
|
||||||
95
src/abi.zig
95
src/abi.zig
|
|
@ -310,51 +310,66 @@ const dur = @import("Duration.zig");
|
||||||
const ins = @import("Instant.zig");
|
const ins = @import("Instant.zig");
|
||||||
|
|
||||||
pub const to = struct {
|
pub const to = struct {
|
||||||
pub fn toTimeZone(val: anytype) c.TimeZone {
|
pub fn toArithmeticOverflow(val: anytype) c.ArithmeticOverflow {
|
||||||
return val._inner;
|
return switch (val) {
|
||||||
}
|
.constrain => c.ArithmeticOverflow_Constrain,
|
||||||
|
.reject => c.ArithmeticOverflow_Reject,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn toDisambiguation(d: anytype) c.Disambiguation {
|
pub fn toShowCalendar(val: anytype) c.ShowCalendar {
|
||||||
return switch (d) {
|
return switch (val) {
|
||||||
.compatible => c.Disambiguation_Compatible,
|
.auto => c.ShowCalendar_Auto,
|
||||||
.earlier => c.Disambiguation_Earlier,
|
.always => c.ShowCalendar_Always,
|
||||||
.later => c.Disambiguation_Later,
|
.never => c.ShowCalendar_Never,
|
||||||
.reject => c.Disambiguation_Reject,
|
.critical => c.ShowCalendar_Critical,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
pub fn toTimeZone(val: anytype) c.TimeZone {
|
||||||
|
return val._inner;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn toOffsetDisambiguation(o: anytype) c.OffsetDisambiguation {
|
pub fn toDisambiguation(d: anytype) c.Disambiguation {
|
||||||
return switch (o) {
|
return switch (d) {
|
||||||
.use_offset => c.OffsetDisambiguation_Use,
|
.compatible => c.Disambiguation_Compatible,
|
||||||
.prefer_offset => c.OffsetDisambiguation_Prefer,
|
.earlier => c.Disambiguation_Earlier,
|
||||||
.ignore_offset => c.OffsetDisambiguation_Ignore,
|
.later => c.Disambiguation_Later,
|
||||||
.reject => c.OffsetDisambiguation_Reject,
|
.reject => c.Disambiguation_Reject,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn calendarDisplay(cd: anytype) c.DisplayCalendar {
|
pub fn toOffsetDisambiguation(o: anytype) c.OffsetDisambiguation {
|
||||||
return switch (cd) {
|
return switch (o) {
|
||||||
.auto => c.DisplayCalendar_Auto,
|
.use_offset => c.OffsetDisambiguation_Use,
|
||||||
.always => c.DisplayCalendar_Always,
|
.prefer_offset => c.OffsetDisambiguation_Prefer,
|
||||||
.never => c.DisplayCalendar_Never,
|
.ignore_offset => c.OffsetDisambiguation_Ignore,
|
||||||
.critical => c.DisplayCalendar_Critical,
|
.reject => c.OffsetDisambiguation_Reject,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn displayOffset(o: anytype) c.DisplayOffset {
|
pub fn calendarDisplay(cd: anytype) c.DisplayCalendar {
|
||||||
return switch (o) {
|
return switch (cd) {
|
||||||
.auto => c.DisplayOffset_Auto,
|
.auto => c.DisplayCalendar_Auto,
|
||||||
.never => c.DisplayOffset_Never,
|
.always => c.DisplayCalendar_Always,
|
||||||
};
|
.never => c.DisplayCalendar_Never,
|
||||||
}
|
.critical => c.DisplayCalendar_Critical,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn toDisplayTimeZone(val: anytype) c.DisplayTimeZone {
|
pub fn displayOffset(o: anytype) c.DisplayOffset {
|
||||||
return switch (val) {
|
return switch (o) {
|
||||||
.auto => c.DisplayTimeZone_Auto,
|
.auto => c.DisplayOffset_Auto,
|
||||||
.never => c.DisplayTimeZone_Never,
|
.never => c.DisplayOffset_Never,
|
||||||
.critical => c.DisplayTimeZone_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 unit(opt: ?t.Unit) ?c.Unit {
|
pub fn unit(opt: ?t.Unit) ?c.Unit {
|
||||||
return if (opt) |u| @as(c.Unit, @intCast(to.unitToCApi(u))) else null;
|
return if (opt) |u| @as(c.Unit, @intCast(to.unitToCApi(u))) else null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue