llogiq.github.io
...With some investment
into optimizations, matching or exceeding C’s speed should be possible in most
cases. However, Rust makes some tradeoffs for different reasons than sheer
speed, so here’s a handy list of some things that may bite you and how you can
speed them up.
Before we...
News & Blog Posts
2017-06-06
~8 min read
asquera.de
...racer complete std::io::B
You should see several matches from this. At this point racer is set up and ready to be used in your editor or with rls.
rls
Why do we want this? It enables a much richer development experience and extends on the capabilities of racer...
News & Blog Posts
2017-03-07
~12 min read
developerlife.com
...let command_to_run_with_each_selection =
match maybe_command_to_run_with_each_selection {
Some(it) => it,
None => {
print_help_for_subcommand_and_option(
"select-from-list",
"command-to-run-with-each-selection",
)
.ok();
let mut line_editor = Reedline::create();
let prompt = DefaultPrompt {
left_prompt: DefaultPromptSegment::Basic(
"Enter command...
Rust Walkthroughs
2023-09-20
~7 min read
dpbriggs.ca
...There's no way to express x7 functions in terms of MyData
let res = match expr {
Expr::Num(i) => MyData::Int(i.to_u64()?), // to_u64 is a ExprHelper method
Expr::String(s) => MyData::String(s.clone()),
unknown_type => {
let err_msg = format!("{} cannot be converted to MyData", unknown_type...
Rust Walkthroughs
2021-01-06
~12 min read
vorner.github.io
...use signal_hook::SIGHUP;
use signal_hook::iterator::Signals;
load_initial_config()?;
let signals = Signals::new(&[SIGHUP])?;
thread::spawn(move || {
for signal in &signals {
match signal {
SIGHUP => {
if Err(e) = try_config_reload() {
error!("Failed to reload configuration: {}", e);
}
},
_ => unreachable!(),
}
}
});
Alternatively, the program can have some way to talk to...
News & Blog Posts
2019-08-13
~13 min read
branan.github.io
...PortName) -> Port {
let gate = match port {
PortName::B => ClockGate::new(5, 10),
PortName::C => ClockGate::new(5, 11),
};
if gate.gate.read() != 0 {
panic!("Cannot create Port instance; it is already in use");
}
gate.gate.write(1);
unsafe {
Port::new(port, gate)
}
}
}
The new ClockGate struct uses the bitband to...
News & Blog Posts
2017-05-09
~13 min read
dwrensha.github.io
...pub mod text {
/// Wrapper around utf-8 encoded text.
/// This is defined as a tuple struct to allow pattern matching
/// on it via byte literals (for example `text::Reader(b"hello")`).
#[derive(Copy, Clone, PartialEq)]
pub struct Reader<'a>(pub &'a [u8]);
impl<'a> Reader<'a> {
pub fn as_bytes...
Project/Tooling Updates
2023-09-06
~3 min read
www.shuttle.rs
...The Error trait vs Results and enums#
One thing when using an enum is we can use match to branch on the enum
error variants. On the other hand, with the dyn trait unless you go down
the down casting path it is very hard to get specific information about...
Observations/Thoughts
2022-07-06
~8 min read
hackernoon.com
...Again, we destructure that Option by using the if let pattern matching syntax which will execute the block if the function returns “some account”. If it doesn’t, we drop an error message. After the pre-checks follows the implementation of the transaction’s specific logic pieces:The statement match...
Learn More Rust
2020-08-18
~41 min read
paytonrules.com
...Choose a GDNativeLibrary and give it the name rust_library.tres (to match what I have). Select it in the FileSystem after you create it, and you should see the Platform window appear on the bottom of the screen. Add your built library by finding your platform (for me this...
News & Blog Posts
2020-07-08
~26 min read
fractalfir.github.io
...The compiler does not support 128 bit matches? Cool, a bunch of if’s it is.
if val == 0 {
// Do sth
} else if val == 1{
// Do sth else
} else if val == 2{
// Do other thing
}/*...*/
else{
// Do yet another thing
}
Inline causes trouble? Well, out it goes.
/*#[inline(always)]*/ // Who...
Observations/Thoughts
2025-07-09
~22 min read
blog.veeso.dev
...Command, desc: &str) -> Result<(), String> { println!("running {:?}", command); let status = command.status(); let verbose_error = match status { Ok(status) if status.success() => return Ok(()), Ok(status) => format!( "'{exe}' reported failure with {status}", exe = command.get_program().to_string_lossy() ), Err(failed) => match failed.kind() { std::io::ErrorKind::NotFound => format!( "Command...
Rust Walkthroughs
2025-03-26
~10 min read
www.tockos.org
...will not compile
let external : &mut NumOrPointer;
match external {
Pointer(internal) => {
// This would violate safety and
// write to memory at 0xdeadbeef
*external = Num(0xdeadbeef);
*internal = 12345; // Kaboom
},
//...
}
// Equivalent C
// compiles without warning
union NumOrPointer* external;
uint32_t* numptr = &external->Num;
*numptr = 0xdeadbeef;
*external->Pointer = 12345;
But operating system kernels depend...
News & Blog Posts
2017-08-08
~8 min read
wangjunfei.com
...For example, when calculating the wire format size of a protocol value, I can use a match statement:
12345678910111213pub fn size(&self) -> i32 { match self { ProtocolType::Bool(bool) => bool.wire_format_size() as i32, ProtocolType::I8(i8) => i8.wire_format_size() as i32, ProtocolType::Array(array) => array.size() as i32...
Rust Walkthroughs
2025-06-25
~17 min read
www.infoq.com
...It's taken a few thorough redesigns but CXX on Cargo now comes close to matching the experience of CXX in a natively polyglot build system. That pleasantly encompasses Rust depending on C++, C++ depending on Rust, and C++ depending on C++ from other crates.
InfoQ: How would you describe...
Miscellaneous
2020-12-09
~3 min read
github.com
...Ok(())
}
fn main() -> () {
use std::process::exit;
use libc::{EXIT_SUCCESS, EXIT_FAILURE};
exit(match inner_main() {
Ok(_) => EXIT_SUCCESS,
Err(ref err) => {
let progname = get_program_name();
eprintln!("{}: {}\n", progname, err);
EXIT_FAILURE
}
})
}
```
These problems can be solved by generalizing the return type of `main`
and test functions.
[csv...
RFC 1937
RFC
2017-02-22
~21 min read
huonw.github.io
...Option<X>, transformer: ...) -> Option<Y> {
match option {
Some(x) => Some(transformer(x)), // (closure syntax for now)
None => None,
}
}
We need to fill in the ... with something that transforms an X into
a Y. The biggest constraint for perfectly replacing Option::map is
that it needs to be generic in some...
Notable Links
2015-05-18
~23 min read
thunderseethe.dev
...AstTypeVar is a simple wrapper enum to allow this (like TyApp):enum AstTypeVar {
Ty(ast::TypeVar),
Row(ast::RowVar),
}
It provides a single helper method kind():impl AstTypeVar {
fn kind(&self) -> Kind {
match self {
AstTypeVar::Ty(_) => Kind::Type,
AstTypeVar::Row(_) => Kind::Row,
}
}
}
We found this method used in the construction...
Observations/Thoughts
2025-02-19
~11 min read
developerlife.com
...InvalidDigit }
/// ```
#[test]
fn test() -> Result<(), Box<dyn std::error::Error>> {
fn return_error_result() -> Result<u32, std::num::ParseIntError> {
"1.2".parse::<u32>()
}
fn run() -> Result<(), Box<dyn std::error::Error>> {
// It is as if the `?` is turned into the following code.
// let result = match result {
// Ok(value) => value,
// Err...
Rust Walkthroughs
2024-06-12
~7 min read
www.techofnote.com
...It then returns true if the total matches the second argument k.
In this example, all the ints are set to 1, so it effectively checks whether the number of true bools is 0, 1 or 2 respectively.
Finally, we check that the line is continuous, and starts/ends at...
Observations/Thoughts
2022-08-31
~7 min read