neikos.me
...post "/:id" => {
let mut chain = Chain::new(controllers::user::update);
chain.link_before(Authorizer::new(
IsOwnerOf::<User>::new()
));
chain
},
};
let mut mount = Mount::new();
mount.mount("/user", user_router);
let server = Iron::new(mount);
match server.http("0.0.0.0:3000") {
Ok(()) => { /*Listening blocks the thread */ }
Err(e) => {
println...
Blog Posts
2016-10-11
~8 min read
ianjk.com
...let path = path.replace("%20", " ");
let path = if path.ends_with("/") {
Path::new(root_path).join(Path::new(&format!(
"{}{}",
path.trim_start_matches('/'),
"index.html"
)))
} else {
Path::new(root_path).join(path.trim_matches('/'))
};
let extension = path.extension().and_then(OsStr::to_str);
// If no extension is specified assume html...
Observations/Thoughts
2020-09-16
~8 min read
polyfractal.com
...bunch of code to load the file, parse the toml ... //
// Once we have a Toml Table, we can call ::decode and
// serialize straight into Config
let config = Value::Table(toml.unwrap());
match toml::decode(config) {
Some(t) => t,
None => panic!("Error while deserializing config")
}
}
NetworkHandler
Once the config has been...
From the Blogosphere
2015-09-07
~8 min read
bitbucket.org
...The second and
third statements identify the file or blob by matching magic numbers.
In all three cases, the result is the string "image/jpeg".
char *mimetype = mimty_file("appendix/samples/cat.jpg");
char *mimetype = mimty_file("appendix/samples/cat");
char *mimetype = mimty_blob(((uint8_t [3]) {0xff, 0xd8, 0xff...
New Releases & Project Updates
2015-06-29
~1 min read
stevedonovan.github.io
...The match operator matches types explicitly
and this is where s.as_str() is still necessary - &s would not work here:
let s = "hello".to_string();
...
match s.as_str() {
"hello" => {....},
"dolly" => {....},
....
}
It’s idiomatic to use string slices in function arguments, knowing that
&String will convert to &str.
Deref...
News & Blog Posts
2019-12-17
~16 min read
geeklaunch.io
...u32 = match Some(1) {
Some(x) => x,
None => return, // `return` is of type never
};Although the syntax is still experimental, the never type is denoted with the exclamation mark !. In the meantime, you can use Infallible as an alternative.The never type can be useful when implementing a trait that...
Rust Walkthroughs
2023-02-22
~5 min read
cliffle.com
...For instance, here’s a simple one:
#[derive(Default)]
enum State {
#[default]
Begin,
PinHigh,
PinLow,
Done,
}
impl State {
fn step(&mut self) -> bool {
match self {
Self::Begin => {
set_pin_high();
*self = Self::PinHigh;
false
}
Self::PinHigh => {
set_pin_low();
*self = Self::PinLow;
false
}
Self::PinLow => {
tristate_pin();
*self = Self::Done...
Observations/Thoughts
2023-07-12
~9 min read
dev.to
...Name) {
match name {
Name::Empty => println!("Hello, {}!", Name::default()),
Name::Is(value) => println!("Hello, {}!", value),
}
}
greet_name(Name::Empty);
greet_name(Name::Is(String::from("Ferris")));
// Hello, world!
// Hello, Ferris!
Enter fullscreen mode
Exit fullscreen mode
I personally prefer the third approach for its readability, but it requires some work...
Learn Standard Rust
2020-09-23
~2 min read
www.lpalmieri.com
...Expected range of matching incoming requests: == 1
Number of matched incoming requests: 0'
Notice that, on failure, wiremock gives us a detailed breakdown of what happened: we expected an incoming request, we received none.
Let's fix that.
Green test
Our handler looks like this right now:
//! src/routes/subscriptions...
Rust Walkthroughs
2021-03-17
~44 min read
hermanradtke.com
...To get usable results from our parser, we must convert (or map) a matched sequence of bytes into the type that we want. Knowing this, let us start looking at how to parse text input.
The bread and butter of our parsing is going to be the use of the...
News & Blog Posts
2016-08-09
~5 min read
blog.orhun.dev
...It is because we allowed Option types by removing the serde attribute so we should update the generic parameter from String to Option<String> in our expected claims data in the script:
- match VerifyWithKey::<Token<Header, BTreeMap<String, String>, _>>::verify_with_key(
+ match VerifyWithKey::<Token<Header, BTreeMap<String, Option<String...
Observations/Thoughts
2022-04-27
~11 min read
siciarz.net
...We can match
on its variants to handle both the happy path and error cases in a very
explicit, if not verbose, way. To address the verbosity, there was a try!
macro that cut down on a lot of pattern matching boilerplate. And as of now
we have an even...
24 Days of Rust
2016-12-20
~5 min read
academy.fpblock.com
...Sum types of records
Rust's enum system, particularly when combined with pattern matching,
feels more robust than Haskell's sum types of records. When defining
sum types of records in Haskell, there is a possibility of introducing
partial record accessors which can cause runtime crashes, though
recent versions of...
Miscellaneous
2025-07-02
~13 min read
tokio.rs
...Value::Structable(v) => v.visit(self),
// Ignore other patterns
_ => {}
}
}
fn visit_named_fields(&mut self, named_values: &NamedValues<'_>) {
// We only care about `accept_encoding`
match named_values.get_by_name("accept_encoding") {
Some(Value::Listable(accept_encoding)) => {
// Create the `VisitAcceptEncoding` instance to visit
// the items in `Listable`.
let mut visit...
Project/Tooling Updates
2021-05-26
~5 min read
mary.codes
...let n = &doc.resolve_reference(&node);
// Matches the node by reference and then generates coordinates.
match n {
osm::Reference::Node(node) => {
let point = process_points(node, &bounds, width, height);
coords.push(&point);
},
_ => {}
}
}
coords
}
I need to call this function from process_ways.
#[wasm_bindgen]
pub fn process_ways(text: String...
Rust Walkthroughs
2024-02-21
~15 min read
blog.yossarian.net
...bitstream blocks that describe an LLVM module may themselves
contain a BLOCKINFO block, which in turn can define multiple abbreviations
for any subsequent blocks that match the block IDs specified by the BLOCKINFO.
If all of this indirection and abbreviation wasn’t complicated enough, the
bitstream container format uses three...
Rust Walkthroughs
2021-08-18
~9 min read
doc.rust-lang.org
...Only the test with the name one_hundred ran; the other two tests didn’t match that name. The test output lets us know we had more tests that didn’t run by displaying 2 filtered out at the end.
We can’t specify the names of multiple tests in...
The Rust Programming Language
Book
2024-02-01
~5 min read
seanmonstar.com
...In doing so, it expresses a strong opinion, which might not match your previous experiences, but I believe it manages to do something really special.
I’m super excited to reveal warp, a joint project with @carllerche.
Background
What makes warp different?
I’ve been working on web servers for...
News & Blog Posts
2018-08-07
~5 min read
notes.iveselov.info
...Why? I don't know for sure, but I suspect that we may want to do certain lookaheads while parsing and this means invoking the closure and then backtracking if it doesn't match. But this mean we would have spoiled the parser closure and can't use it again...
News & Blog Posts
2020-07-21
~5 min read
doc.rust-lang.org
...match self.0.front_mut().and_then(Iterator::next) {
Some(State::Elem(elem)) => return Some(elem),
Some(State::Node(node)) => self.0.push_front(node.iter_mut()),
None => {
self.0.pop_front()?;
}
}
}
}
}
impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
fn next_back(&mut self) -> Option<Self::Item> {
loop {
match...
The Rustonomicon
Book
2024-01-01
~5 min read