[][src]Macro fruity::nsstring

macro_rules! nsstring {
    ($s:expr) => { ... };
}

Creates an NSString from a static string.

Feature Flag

This macro is defined in foundation, which requires the foundation feature flag.

Examples

This macro takes a "string" literal as the argument:

let hello = fruity::nsstring!("hello");

assert_eq!(hello.to_string(), "hello");

The result of this macro can even be used to create static values:

static WORLD: NSString = fruity::nsstring!("world");

assert_eq!(WORLD.to_string(), "world");

Note that the result cannot be used in a const because it refers to static data outside of this library.

Validity Checking

Because the string data must be a valid C string, having null bytes inside it causes a compile error:

This example deliberately fails to compile
let s = fruity::nsstring!("ab\0cd");

Runtime Cost

None.

The result is equivalent to @"string" syntax in Objective-C.

Because of that, this should be preferred over NSString::from_str where possible.

Compile-time Cost

Minimal.

This is implemented entirely with const evaluation. It is not a procedural macro that requires dependencies for parsing.