Reputation: 559
I tried using LAPACK bindings for Rust when I came over some syntax that I could not find anything about.
The example code from https://github.com/stainless-steel/lapack:
let n = 3;
let mut a = vec![3.0, 1.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 3.0];
let mut w = vec![0.0; n];
let mut work = vec![0.0; 4 * n];
let lwork = 4 * n as isize;
let mut info = 0;
lapack::dsyev(b'V', b'U', n, &mut a, n, &mut w, &mut work, lwork, &mut info);
for (one, another) in w.iter().zip(&[2.0, 2.0, 5.0]) {
assert!((one - another).abs() < 1e-14);
}
What does b'V' and b'U' mean?
Upvotes: 1
Views: 879
Reputation: 15002
It creates a u8
value with the ASCII value of the char between quote.
For ASCII literals, it's the same as writing 'V' as u8
.
Also, the b
prefix on a double quoted string will create a byte array containing the UTF8 content of the string.
let s: &[u8; 11] = b"Hello world";
Upvotes: 4
Reputation: 430991
b'A'
means to create a byte literal. Specifically, it will be a u8
containing the ASCII value of the character:
fn main() {
let what = b'a';
println!("{}", what);
// let () = what;
}
The commented line shows you how to find the type.
b"hello"
is similar, but produces a reference to an array of u8
, a byte string:
fn main() {
let what = b"hello";
println!("{:?}", what);
// let () = what;
}
Things like this are documented in the Syntax Index which is currently only available in the nightly version of the docs.
Upvotes: 4