pub struct Args { /* private fields */ }
Expand description
Wrapper over C-style arguments
§Example:
On most targets you can supply own C-style main function.
One of the benefits is that it is no longer necessary to rely on allocating std::env::Args
#![no_main]
#[no_mangle]
pub unsafe extern fn main(argc: std::os::raw::c_int, argv: *const *const u8) -> std::os::raw::c_int {
let args = c_ffi::Args::new(argc as isize, argv).expect("To get function arguments");
0
}
Implementations§
Source§impl Args
impl Args
Sourcepub unsafe fn new(
argc: isize,
argv: *const *const u8,
) -> Result<Self, (usize, Utf8Error)>
pub unsafe fn new( argc: isize, argv: *const *const u8, ) -> Result<Self, (usize, Utf8Error)>
Creates new instance, but verifies that each string inside are UTF-8.
On error returns pair: (string index, Utf8Error)
The function is safe as long as you pass C style main function arguments.
Sourcepub unsafe fn new_unchecked(argc: isize, argv: *const *const u8) -> Self
pub unsafe fn new_unchecked(argc: isize, argv: *const *const u8) -> Self
Unchecked version of Args::new
Do it on your own risk
Sourcepub unsafe fn get_str_by_index(&self, index: usize) -> &str
pub unsafe fn get_str_by_index(&self, index: usize) -> &str
Retrieves string by index.
No checks, 100% unsafe.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Args
impl RefUnwindSafe for Args
impl !Send for Args
impl !Sync for Args
impl Unpin for Args
impl UnwindSafe for Args
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more