chore: shorten `orelse @panic` to `.?`
This commit is contained in:
parent
f75479bf8f
commit
86f675a8d2
|
@ -44,8 +44,7 @@ pub fn init(allocator: Allocator, rom_path: []const u8, save_path: ?[]const u8)
|
||||||
pub fn setupGpio(self: *Self) void {
|
pub fn setupGpio(self: *Self) void {
|
||||||
switch (self.gpio.device.kind) {
|
switch (self.gpio.device.kind) {
|
||||||
.Rtc => {
|
.Rtc => {
|
||||||
const ptr = self.gpio.device.ptr orelse @panic("RTC ptr is missing despite GPIO Device Kind");
|
const clock = @ptrCast(*Clock, @alignCast(@alignOf(*Clock), self.gpio.device.ptr.?));
|
||||||
const clock = @ptrCast(*Clock, @alignCast(@alignOf(*Clock), ptr));
|
|
||||||
Clock.init(clock, &self.gpio);
|
Clock.init(clock, &self.gpio);
|
||||||
},
|
},
|
||||||
.None => {},
|
.None => {},
|
||||||
|
@ -265,8 +264,7 @@ const Gpio = struct {
|
||||||
fn step(self: *Device, value: u4) void {
|
fn step(self: *Device, value: u4) void {
|
||||||
switch (self.kind) {
|
switch (self.kind) {
|
||||||
.Rtc => {
|
.Rtc => {
|
||||||
const ptr = self.ptr orelse @panic("Device.ptr should != null when Device.kind == .Rtc");
|
const clock = @ptrCast(*Clock, @alignCast(@alignOf(*Clock), self.ptr.?));
|
||||||
const clock = @ptrCast(*Clock, @alignCast(@alignOf(*Clock), ptr));
|
|
||||||
|
|
||||||
clock.step(Clock.GpioData{ .raw = value });
|
clock.step(Clock.GpioData{ .raw = value });
|
||||||
},
|
},
|
||||||
|
@ -304,8 +302,7 @@ const Gpio = struct {
|
||||||
fn deinit(self: This, allocator: Allocator) void {
|
fn deinit(self: This, allocator: Allocator) void {
|
||||||
switch (self.device.kind) {
|
switch (self.device.kind) {
|
||||||
.Rtc => {
|
.Rtc => {
|
||||||
const ptr = self.device.ptr orelse @panic("Device.ptr should != null when Device.kind == .Rtc");
|
allocator.destroy(@ptrCast(*Clock, @alignCast(@alignOf(*Clock), self.device.ptr.?)));
|
||||||
allocator.destroy(@ptrCast(*Clock, @alignCast(@alignOf(*Clock), ptr)));
|
|
||||||
},
|
},
|
||||||
.None => {},
|
.None => {},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue