www.nahua.dev
...TokenStream = match &self.col_type {
ColumnType::Char(_)
...
ColumnType::Float(_) => "f32".to_owned(),
ColumnType::Double(_) => "f64".to_owned(),
ColumnType::Json | ColumnType::JsonBinary => "Json".to_owned(),
ColumnType::Date => match date_time_crate {
DateTimeCrate::Chrono => "Date".to_owned(),
DateTimeCrate::Time => "TimeDate".to_owned(),
},
ColumnType::Time(_) => match date_time_crate {
DateTimeCrate::Chrono => "Time".to...
Rust Walkthroughs
2022-06-29
~17 min read
mainmatter.com
...PdfWriterConfiguration) -> Result<Term, RustlerError> {
match priv_create_pdf(config) {
Ok(()) => Ok(atoms::ok().to_term(env)),
Err(ref error) => return Err(RustlerError::Term(Box::new(io_error_to_term(error)))),
}
}
fn priv_create_pdf(config: PdfWriterConfiguration) -> Result<(), std::io::Error> {}create_pdf is slightly more complicated as it involves some...
Rust Walkthroughs
2023-02-08
~8 min read
rtoch.com
...LinkedList<Vec<Operation>> = LinkedList::new();
stack.push_back(Vec::new());
for token in tokens {
let cur_operations = stack.back_mut().expect("Stack should not be empty!");
match token {
Token::MoveRight => {
if let Some(Operation::MoveRight(x)) = cur_operations.last_mut() {
*x += 1;
} else {
cur_operations.push(Operation::MoveRight(1))
}
}
Token...
Miscellaneous
2022-03-23
~7 min read
smista.ai
...MemoryArgs) -> Result<String, Self::Error> {
let MemoryArgs {
op,
scope,
key,
value,
} = args;
match op {
MemoryOp::Record => {
let value = value.ok_or(MemoryToolError::MissingValue)?;
match scope {
MemoryScope::User => {
self.storage
.put_user_memory(Some(key.clone()), value)
.await?;
}
MemoryScope::Session => {
self.storage
.put_session_memory(Some(key.clone()), value)
.await?;
}
}
Ok...
Rust Walkthroughs
2026-06-17
~7 min read
doc.rust-lang.org
...algebraic data types, pattern matching, type inference, semicolon statement separation
• C++: references, RAII, smart pointers, move semantics, monomorphization, memory model
• ML Kit, Cyclone: region based memory management
• Haskell (GHC): typeclasses, type families
• Newsqueak, Alef, Limbo: channels, concurrency
• Erlang: message passing, thread failure, ,
• Swift: optional bindings
• Scheme: hygienic macros
• C#: attributes...
The Rust Reference
Book
2024-01-01
~1 min read
jackh726.github.io
...fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
match (&t,) {
((u,),) => u,
}
}
fn main() {
let y = Box::new((42,));
let x = transmute_lifetime(&y);
}
Stable emits the following error:
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> src/main.rs:2:11
|
2 | match...
Observations/Thoughts
2022-06-15
~13 min read
github.com
...In the MIR, all drops are explicit, including those that result from
panics and unwinding.
- **How matches are desugared.** Reasoning about matches has been a
traditional source of complexity. Matches combine traversing types
with borrows, moves, and all sorts of other things, depending on the
precise patterns in use. This...
RFC 1211
RFC
2015-07-14
~27 min read
doc.rust-lang.org
pub fn connect_addr(&self, socket_addr: &SocketAddr) -> io::Result<()>
...Examples
use std::os::unix::net::{UnixDatagram};
fn main() -> std::io::Result<()> {
let bound = UnixDatagram::bind("/path/to/socket")?;
let addr = bound.local_addr()?;
let sock = UnixDatagram::unbound()?;
match sock.connect_addr(&addr) {
Ok(sock) => sock,
Err(e) => {
println!("Couldn't connect: {e:?}");
return Err(e)
}
};
Ok(())
}
method
std
Stable since 1.70.0
Version 1.100.0-nightly
integer32.com
...usize) -> Result<&str> {
let s = &s[location..];
match s.find("\n") {
Some(pos) => {
let head = &s[..pos];
Ok((head, location + pos + "\n".len()))
},
None => {
Err(location)
}
}
}
fn main() {
let input = "hello\nworld";
assert_eq!(Ok(("hello", 6)), parse_until_newline(input, 0));
assert_eq!(Err(6), parse_until_newline(input...
News & Blog Posts
2017-02-07
~5 min read
durch.github.io
...String } let rsa_key = match RSAKey::from_pem("random_rsa_for_testing") { Ok(x) => x, Err(e) => panic!("{}", e) }; let jwt = Jwt::new(ExampleStruct{field: String::from("test")}, rsa_key, None); println!("{}", jwt); }
Crate
v0.9.0
2025-12-09
docs.rs
...Example let mut es = EventSource::get("http://localhost:8000/events"); while let Some(event) = es.next().await { match event { Ok(Event::Open) => println!("Connection Open!"), Ok(Event::Message(message)) => println!("Message: {:#?}", message), Err(err) => { println!("Error: {}", err); es.close(); } } } License: MIT OR Apache-2.0
Crate
v0.6.0
2024-03-29
rust-lang.github.io
...Attribute
invocations can only match the attr rules, and non-attribute invocations can
only match the non-attr rules. This allows adding attr rules to an existing
macro without breaking backwards compatibility.
An attribute macro may emit code containing another attribute, including one
provided by an attribute macro. An attribute...
Compiler
2025-08-13
~7 min read
docs.rs
...The version of prost used by the library is re-exported as tink_proto::prost , to allow library users to get a precise version match. Features The json feature enables serde_json based serialization of the structures. License Apache License, Version 2.0 Disclaimer This is not an officially supported...
Crate
v0.3.0
2024-11-28
rust.code-maven.com
...let database_folder = match std::env::var("DATABASE_PATH") {
Ok(val) => std::path::PathBuf::from(val),
Err(_) => {
let current_dir = std::env::current_dir().unwrap();
current_dir.join("db")
}
};
Connect to the database on the filesystem
Then we connect to the database folder via the RocksDb driver.
let db = Surreal...
Miscellaneous
2024-01-17
~5 min read
docs.rs
...let len = BENCHMARKS.len(); } The compiler will require that the static element type matches with the element type of the distributed slice. If the two do not match, the program will not compile: #[distributed_slice(BENCHMARKS)] static BENCH_WTF: usize = 999; error[E0308]: mismatched types --> src/distributed_slice.rs:65...
Crate
v0.3.37
2026-07-18
doc.rust-lang.org
pub fn contains<Q>(&self, value: &Q) -> bool
...The value may be any borrowed form of the set's value type, but Hash and Eq on the borrowed form must match those for the value type.
Examples
use std::collections::HashSet;
let set = HashSet::from([1, 2, 3]);
assert_eq!(set.contains(&1), true);
assert_eq!(set.contains...
method
std
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn connect_addr(socket_addr: &SocketAddr) -> io::Result<UnixStream>
...Examples
use std::os::unix::net::{UnixListener, UnixStream};
fn main() -> std::io::Result<()> {
let listener = UnixListener::bind("/path/to/the/socket")?;
let addr = listener.local_addr()?;
let sock = match UnixStream::connect_addr(&addr) {
Ok(sock) => sock,
Err(e) => {
println!("Couldn't connect: {e:?}");
return Err(e)
}
};
Ok(())
}
associated_function
std
Stable since 1.70.0
Version 1.100.0-nightly
info.varnish-software.com
...Let's have a look at that match statement again. I told you it had some nice features, but didn't go too deep about them. One very cool aspect is destructuring, that we'll use. Match is able to give you direct access to element of a struct or...
News & Blog Posts
2016-04-11
~11 min read
docs.rs
...Deserializer<'de>, { UntaggedEnumVisitor::new() .bool(|b| match b { false => Ok(LinkTimeOptimization::ThinLocal), true => Ok(LinkTimeOptimization::Fat), }) .string(|string| match string { "fat" => Ok(LinkTimeOptimization::Fat), "thin" => Ok(LinkTimeOptimization::Thin), "off" => Ok(LinkTimeOptimization::Off), _ => Err(serde::de::Error::invalid_value( Unexpected::Str(string), &r#""fat" or "thin" or "off""#, )), }) .deserialize(deserializer) } } License...
Crate
v0.1.9
2025-09-14