1use core::{
4 ffi::{CStr, c_char},
5 fmt::Debug,
6 ops::Deref,
7};
8
9#[repr(transparent)]
11pub struct Arg(*const c_char);
12
13impl Debug for Arg {
14 #[inline]
15 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
16 self.deref().fmt(f)
17 }
18}
19
20impl From<&'static CStr> for Arg {
21 #[inline]
22 fn from(arg: &'static CStr) -> Self {
23 Self(arg.as_ptr())
24 }
25}
26
27impl Deref for Arg {
28 type Target = CStr;
29 #[inline]
30 fn deref(&self) -> &Self::Target {
31 unsafe { CStr::from_ptr(self.0) }
32 }
33}
34
35#[cfg(feature = "native-simulator")]
36impl Arg {
37 pub fn new(arg: &str) -> Self {
38 Self {
39 0: (arg.as_ptr()) as *const c_char,
40 }
41 }
42}
43
44static mut ARGV: &'static [Arg] = &[];
45
46#[inline]
52pub fn argv() -> &'static [Arg] {
53 unsafe { ARGV }
54}
55
56#[doc(hidden)]
58#[inline]
59pub unsafe fn set_argv(argv: &'static [Arg]) {
60 unsafe { ARGV = argv }
61}