Skip to content

Commit

Permalink
treewide: More Rust 1.79 simplifications
Browse files Browse the repository at this point in the history
Merges: #116
  • Loading branch information
chrysn authored Aug 29, 2024
2 parents fcfceb6 + a4b15ce commit 3d280a4
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ mutex-trait = "0.2"

bare-metal = "1"

# Only used for shell, where a macro is described to take a string literal and
# in the macro implementation turns it into a CStr.
cstr = "^0.2.11"

heapless = "^0.8"
Expand Down
2 changes: 1 addition & 1 deletion src/gcoap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ where
/// [coap_handler::Handler], you can wrap it in [crate::coap_handler::GcoapHandler] to for adaptation.
pub fn new_catch_all(handler: &'a mut H) -> Self {
Self::new(
cstr::cstr!("/"),
c"/",
riot_sys::COAP_GET
| riot_sys::COAP_POST
| riot_sys::COAP_PUT
Expand Down
2 changes: 1 addition & 1 deletion src/gnrc/ipv6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl<M: Mode> Pktsnip<M> {
// unsafe: C API, and requirement on a Pktsnip that typed snips follow that type's
// conventions
let ptr = unsafe { riot_sys::gnrc_ipv6_get_header(self.ptr) };
if ptr == 0 as _ {
if ptr.is_null() {
None
} else {
// unsafe: Header is a transparent wrapper around the actual ipv6_hdr_t, and the
Expand Down
2 changes: 1 addition & 1 deletion src/gnrc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Netif {

#[doc(alias = "gnrc_netif_get_by_pid")]
pub fn by_pid(pid: KernelPID) -> Option<Self> {
const NULL: *mut riot_sys::gnrc_netif_t = 0 as _;
const NULL: *mut riot_sys::gnrc_netif_t = core::ptr::null_mut();
// Not using as_ref: We can't guarantee that even for the short period between we're making
// it into a reference and casting it back to a pointer again, it is not used by anyone
// else
Expand Down
2 changes: 1 addition & 1 deletion src/gnrc_pktbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl<'a> Pktsnip<Shared> {
// unsafe: The C functions justify the new type
unsafe {
let new = riot_sys::gnrc_pktbuf_start_write(self.to_ptr());
if new == 0 as _ {
if new.is_null() {
Err(NotEnoughSpace)
} else {
Ok(Pktsnip::<Writable>::from_ptr(new))
Expand Down
2 changes: 1 addition & 1 deletion src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn panic(info: &::core::panic::PanicInfo) -> ! {
unsafe {
riot_sys::core_panic(
riot_sys::core_panic_t_PANIC_GENERAL_ERROR,
cstr::cstr!("RUST PANIC").as_ptr() as _,
c"RUST PANIC".as_ptr() as _,
)
};
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/saul/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ where
) -> Self {
Registration {
reg: riot_sys::saul_reg_t {
next: 0 as _,
next: core::ptr::null_mut(),
dev: device as *const _ as *mut _,
name: name.map(|n| n.as_ptr() as _).unwrap_or(core::ptr::null()),
driver: &driver.driver as *const _,
Expand Down
2 changes: 1 addition & 1 deletion src/ztimer/periodic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<H: Handler, const HZ: u32> Timer<H, HZ> {
clock.0,
timer.as_mut_ptr(),
Some(Self::callback),
0 as _,
core::ptr::null_mut(),
ticks.0,
);
timer.assume_init()
Expand Down

0 comments on commit 3d280a4

Please sign in to comment.