Skip to content

Commit

Permalink
docs(flipperzero-rs#92): make enhance c_string's lifetime explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
JarvisCraft committed Jul 11, 2023
1 parent 8d3102c commit 7d949d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 1 addition & 2 deletions crates/flipperzero/examples/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ fn main(_args: *mut u8) -> i32 {
// Next, we'll open a file browser dialog and let the user select the file.
let mut dialogs_app = DialogsApp::open();

static EXTENSION: &CStr = cstr!("*");
let file_browser_options = DialogFileBrowserOptions::new(EXTENSION).set_hide_ext(false);
let file_browser_options = DialogFileBrowserOptions::new(cstr!("*")).set_hide_ext(false);
let mut start_path = FuriString::from(path);
let result_path =
dialogs_app.show_file_browser(Some(&mut start_path), Some(&file_browser_options));
Expand Down
11 changes: 6 additions & 5 deletions crates/sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ mod inlines;
)]
mod bindings;

/// Create a static C string of type [`*const c_char`][core::ffi::c_char].
/// Create a static C string of type [`&'static CStr`][`core::ffi::CStr`].
/// Will automatically add a NUL terminator.
pub use cstr::cstr;

/// Create a static C string of type [`*const c_char`][core::ffi::c_char]
/// referring to a `'static` string.
/// Will automatically add a NUL terminator.
// TODO: don't produce intermediate `CStr` whose `length` part we don't use
#[macro_export]
Expand All @@ -39,10 +44,6 @@ macro_rules! c_string {
}};
}

/// Create a static C string of type [`&CStr`][`core::ffi::CStr`].
/// Will automatically add a NUL terminator.
pub use cstr::cstr;

/// Crash the system.
#[macro_export]
macro_rules! crash {
Expand Down

0 comments on commit 7d949d2

Please sign in to comment.