siciarz.net
...extern crate postgres;
use postgres::{Connection, SslMode};
fn main() {
let dsn = "postgresql://rust:rust@localhost/rust";
let conn = match Connection::connect(dsn, &SslMode::None) {
Ok(conn) => conn,
Err(e) => {
println!("Connection error: {}", e);
return;
}
};
}
The Connection type has a few methods related to making queries; perhaps the simplest one is...
24 Days of Rust continues!
2014-12-15
~3 min read
blog.kolo.app
...It only has support for a limited number of types, which don't match Python's data types amazingly well.
Maybe it was time to try a different format. In particular, msgpack was looking attractive:
It is a binary format which optimises for size.
It supports many of the basic...
Rust Walkthroughs
2023-10-11
~8 min read
rocket.rs
...Routes without query parameters now match requests with or without query parameters. Default rankings prefer static paths and routes with query string matches. A native Accept header structure was added. The Accept request header can be retrieved via Request::accept(). All active routes can be retrieved via Rocket::routes(). Response...
News & Blog Posts
2017-07-18
~7 min read
docs.rs
...Install [dependencies] diff = "0.1" Example extern crate diff; fn main() { let left = "foo\nbar\nbaz\nquux"; let right = "foo\nbaz\nbar\nquux"; for diff in diff::lines(left, right) { match diff { diff::Result::Left(l) => println!("-{}", l), diff::Result::Both(l, _) => println!(" {}", l), diff::Result::Right(r) => println!("+{}", r...
Crate
v0.1.13
2022-06-29
doc.rust-lang.org
pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result<UnixDatagram>
...Examples
use std::os::unix::net::{UnixDatagram};
fn main() -> std::io::Result<()> {
let sock1 = UnixDatagram::bind("path/to/socket")?;
let addr = sock1.local_addr()?;
let sock2 = match UnixDatagram::bind_addr(&addr) {
Ok(sock) => sock,
Err(err) => {
println!("Couldn't bind: {err:?}");
return Err(err);
}
};
Ok(())
}
associated_function
std
Stable since 1.70.0
Version 1.100.0-nightly
briankung.dev
...As mentioned before, not_whitespace will match any character that isn’t whitespace, whereas space1 will match a single space and space0 will match zero or one space.
But a few of these are custom parsers that I wrote from nom’s more basic building blocks: pinyin, jyutping, and definitions...
Rust Walkthroughs
2021-12-22
~11 min read
crates.io
...Installation Select a version of kube along matching versions of k8s-openapi and schemars for Kubernetes structs and matching schemas. See also historical Kubernetes versions . [dependencies] kube = { version = "4.2.0", features = ["runtime", "derive"] } k8s-openapi = { version = "0.28.0", features = ["latest", "schemars"] } schemars = { version = "1" } See features for a...
Crate
v4.2.0
2026-07-22
github.com
...cannot move out of borrowed content
--> /Users/jturner/Source/errors/borrowck-move-out-of-vec-tail.rs:30:17
I’m trying to track the ownership of the contents of `tail`, which is borrowed, through this match
statement:
29 | match tail {
In this match, you use an expression of the...
RFC 1644
RFC
2016-06-07
~13 min read
rust-analyzer.github.io
...Your browser does not support the video tag.
#12345 (first contribution) add escapeSequence semantic token type.
#12263 hide type inlay hints for let statements that initialize a closure (enable using rust-analyzer.inlayHints.typeHints.hideClosureInitialization):
#12130 add assist to turn let-else statements into let and match:
Your browser does...
Project/Tooling Updates
2022-05-25
~1 min read
doc.rust-lang.org
pub fn ends_with<P>(&self, child: P) -> bool
...Only considers whole path components to match.
Examples
use std::path::Path;
let path = Path::new("/etc/resolv.conf");
assert!(path.ends_with("resolv.conf"));
assert!(path.ends_with("etc/resolv.conf"));
assert!(path.ends_with("/etc/resolv.conf"));
assert!(!path.ends_with("/resolv.conf"));
assert!(!path.ends_with("conf...
method
std
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
...Default,
{
match map.get_mut(&key) {
Some(value) => value,
None => {
map.insert(key.clone(), V::default());
map.get_mut(&key).unwrap()
}
}
}
Because of the lifetime restrictions imposed, &mut map's lifetime overlaps other mutable borrows, resulting in a compile error:
error[E0499]: cannot borrow `*map` as mutable more than once...
The Rustonomicon
Book
2024-01-01
~2 min read
crates.io
...Installation Select a version of kube along matching versions of k8s-openapi and schemars for Kubernetes structs and matching schemas. See also historical Kubernetes versions . [dependencies] kube = { version = "4.2.0", features = ["runtime", "derive"] } k8s-openapi = { version = "0.28.0", features = ["latest", "schemars"] } schemars = { version = "1" } See features for a...
Crate
v4.2.0
2026-07-22
rust-analyzer.github.io
#3084 better error reporting around workspace loading.
#3102 better error reporting when deserializing wrong config.
#3092 fix error when starting the server immediately after download.
#3100 improved error handling when downloading the server binary.
#3114 fix type inference for match arms of unknown type.
#3121 during auto-import, don’t...
News & Blog Posts
2020-02-18
~1 min read
arXiv
arxiv.org
...Its scalability for these tasks matches or exceeds that of leading Datalog systems. We demonstrate uses in reasoning with knowledge graphs and ontologies with 10^5 to 10^8 input facts, all on a laptop. Nemo is written in Rust and available as a free and open source tool.
Artificial Intelligence
Alex Ivliev, Stefan Ellmauthaler, Lukas Gerlach et al.
2023-08-30
arXiv:2308.15897
doc.rust-lang.org
pub fn back_mut(&mut self) -> Option<&mut T>
...Examples
use std::collections::VecDeque;
let mut d = VecDeque::new();
assert_eq!(d.back(), None);
d.push_back(1);
d.push_back(2);
match d.back_mut() {
Some(x) => *x = 9,
None => (),
}
assert_eq!(d.back(), Some(&9));
method
alloc
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub const fn iter_mut(&mut self) -> IterMut<'_, T>
...Result<u32, &str> = Ok(7);
match x.iter_mut().next() {
Some(v) => *v = 40,
None => {},
}
assert_eq!(x, Ok(40));
let mut x: Result<u32, &str> = Err("nothing!");
assert_eq!(x.iter_mut().next(), None);
method
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub struct Incoming<'a>
...UnixStream) {
// ...
}
fn main() -> std::io::Result<()> {
let listener = UnixListener::bind("/path/to/the/socket")?;
for stream in listener.incoming() {
match stream {
Ok(stream) => {
thread::spawn(|| handle_client(stream));
}
Err(err) => {
break;
}
}
}
Ok(())
}
struct
std
Stable since 1.10.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result<UnixListener>
...Examples
use std::os::unix::net::{UnixListener};
fn main() -> std::io::Result<()> {
let listener1 = UnixListener::bind("path/to/socket")?;
let addr = listener1.local_addr()?;
let listener2 = match UnixListener::bind_addr(&addr) {
Ok(sock) => sock,
Err(err) => {
println!("Couldn't bind: {err:?}");
return Err(err);
}
};
Ok(())
}
associated_function
std
Stable since 1.70.0
Version 1.100.0-nightly
redox-os.org
...Redox was not matching POSIX behavior for file descriptors; when dup is called, the new fd should still refer to the same “file description”, which Redox did not have a concept of. I modified the kernel to match POSIX behavior.
I changed Redox’s target triple (for the gcc toolchain...
News & Blog Posts
2017-08-22
~4 min read
crates.io
...Installation Select a version of kube along matching versions of k8s-openapi and schemars for Kubernetes structs and matching schemas. See also historical Kubernetes versions . [dependencies] kube = { version = "4.0.0", features = ["runtime", "derive"] } k8s-openapi = { version = "0.28.0", features = ["latest", "schemars"] } schemars = { version = "1" } See features for a...
Crate
v4.2.0
2026-07-22