chore: move all binding code to abi
This commit is contained in:
parent
424b437a33
commit
81fcafa67f
4 changed files with 56 additions and 69 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
15
src/abi.zig
15
src/abi.zig
|
|
@ -310,6 +310,21 @@ const dur = @import("Duration.zig");
|
|||
const ins = @import("Instant.zig");
|
||||
|
||||
pub const to = struct {
|
||||
pub fn toArithmeticOverflow(val: anytype) c.ArithmeticOverflow {
|
||||
return switch (val) {
|
||||
.constrain => c.ArithmeticOverflow_Constrain,
|
||||
.reject => c.ArithmeticOverflow_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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue