Struct const_cstr::ConstCStr [] [src]

pub struct ConstCStr {
    pub val: &'static str,
}

A type representing a static C-compatible string, wrapping &'static str.

Note

Prefer the const_cstr! macro to create an instance of this struct over manual initialization. The macro will include the NUL byte for you.

Fields

The wrapped string value. Not intended to be used for manual initialization. Public only to allow initialization by the const_cstr! macro.

Includes the NUL terminating byte. Use to_str() to get an &'static str without the NUL terminating byte.

Methods

impl ConstCStr
[src]

[src]

Returns the wrapped string, without the NUL terminating byte.

Compare to CStr::to_str() which checks that the string is valid UTF-8 first, since it starts from an arbitrary pointer instead of a Rust string slice.

[src]

Returns the wrapped string as a byte slice, without the NUL terminating byte.

[src]

Returns the wrapped string as a byte slice, with* the NUL terminating byte.

[src]

Returns a pointer to the beginning of the wrapped string.

Suitable for passing to any function that expects a C-compatible string. Since the underlying string is guaranteed to be 'static, the pointer should always be valid.

Panics

If the wrapped string is not NUL-terminated. (Unlikely if you used the const_cstr! macro. This is just a sanity check.)

[src]

Returns the wrapped string as an &'static CStr, skipping the length check that CStr::from_ptr() performs (since we know the length already).

Panics

If the wrapped string is not NUL-terminated. (Unlikely if you used the const_cstr! macro. This is just a sanity check.)

Trait Implementations

impl Copy for ConstCStr
[src]

impl Clone for ConstCStr
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for ConstCStr
[src]

[src]

Formats the value using the given formatter.

impl PartialEq for ConstCStr
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl Eq for ConstCStr
[src]

impl PartialOrd for ConstCStr
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Ord for ConstCStr
[src]

[src]

This method returns an Ordering between self and other. Read more

1.22.0
[src]

Compares and returns the maximum of two values. Read more

1.22.0
[src]

Compares and returns the minimum of two values. Read more

impl Hash for ConstCStr
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more