Skip to content

Instantly share code, notes, and snippets.

View nrc's full-sized avatar
🐙
Having a rest

Nick Cameron nrc

🐙
Having a rest
View GitHub Profile
@nrc
nrc / gist:809614adb2bbb38232b7
Last active January 2, 2022 02:03
Borrowing in Rust

When converting from a smart pointer type to a borrowed reference, you need to 'cross-borrow' data. This requires writing &*expr or &**expr, etc. This is usually just annoying - it doesn't help to read or write the code. When writing, you play 'type Tetris', inserting *s until the compiler is happy. When reading it is just line noise. At best, if you are passing a value to a function, it tells you that you are passing a borrowed reference, not owned data. Alternatively, that you are passing by reference, not value.

So, we would like to spare the programmer this burden. The question is how. There have been a few proposals (rust-lang/rfcs#226, rust-lang/rfcs#241, rust-lang/rfcs#248). A central question when evaluating these proposals is whether the programmer should care first about the borrowed-ness of data or about the amount of indirection to the user. I am starting to lean more towards the position of making ownership/borrowing s

@nrc
nrc / tools.md
Last active August 2, 2023 16:40
Rust tooling

Rust developer tools - status and strategy

Availability and quality of developer tools are an important factor in the success of a programming language. C/C++ has remained dominant in the systems space in part because of the huge number of tools tailored to these lanaguages. Succesful modern languages have had excellent tool support (Java in particular, Scala, Javascript, etc.). Finally, LLVM has been successful in part because it is much easier to extend than GCC. So far, Rust has done pretty well with developer tools, we have a compiler which produces good quality code in reasonable time, good support for debug symbols which lets us leverage C++/lanaguge agnostic tools such as debuggers, profilers, etc., there are also syntax highlighting, cross-reference, code completion, and documentation tools.

In this document I want to layout what Rust tools exist and where to find them, highlight opportunities for tool developement in the short and long term, and start a discussion about where to focus our time an

@nrc
nrc / ints.md
Created November 29, 2014 22:29
Integer fallback etc.

Integer types

This is meant to be a summary of the current status and the questions around integer fallback and type names. It's meant to be an objective overview so we can discuss at the work week and have the same starting point. (Obviously I have an opinion here, so it might not be totally objective but I'll try).

Current status

@nrc
nrc / gist:7261e80068115a3ac76c
Last active August 29, 2015 14:24
Method calls
// I think this is every possible way to call a method in Rust.
struct Foo;
impl Foo {
fn m1() {
println!("Hello! m1");
}
fn m2(&self) {
@nrc
nrc / strace.txt
Created October 19, 2015 04:59
strace
execve("/usr/local/bin/cargo", ["cargo", "rustc", "--", "-Ztime-passes"], [/* 24 vars */]) = 0
brk(0) = 0x7ff9443f7000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ff941c74000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/root/rust/x86_64-unknown-linux-gnu/stage2/lib/tls/x86_64/librt.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/root/rust/x86_64-unknown-linux-gnu/stage2/lib/tls/x86_64", 0x7fffac27ac00) = -1 ENOENT (No such file or directory)
open("/root/rust/x86_64-unknown-linux-gnu/stage2/lib/tls/librt.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/root/rust/x86_64-unknown-linux-gnu/stage2/lib/tls", 0x7fffac27ac00) = -1 ENOENT (No such file or directory)
open("/root/rust/x86_64-unknown-linux-gnu/stage2/lib/x86_64/librt.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file
time: 0.013; rss: 62MB parsing
time: 0.003; rss: 62MB configuration 1
time: 0.000; rss: 62MB recursion limit
time: 0.000; rss: 62MB crate injection
time: 0.023; rss: 96MB macro loading
time: 0.001; rss: 98MB plugin loading
time: 0.000; rss: 98MB plugin registration
time: 0.213; rss: 106MB expansion
time: 0.021; rss: 106MB configuration 2
time: 0.000; rss: 106MB gated configuration checking
@nrc
nrc / lists-4.rs
Created September 16, 2016 03:43
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
@nrc
nrc / lists-2.rs
Created September 16, 2016 03:51
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
@nrc
nrc / Abstract v3
Last active July 31, 2017 06:18 — forked from Xanewok/Abstract v3
>>>>>>>>>>>>>>>>>>>>>>>
Teaching an IDE to understand Rust
>>>>>>>>>>>>>>>>>>>>>>>
Abstract
(A concise, engaging description for the public program. Limited to 600 characters.)
IDE support is one of Rust's most requested features. From the 2017 State of Rust Survey:
roughly 30% of Rust users are looking forward to IDE support more than any other feature in 2017 and for 22% of
non-users, lack of IDE support is their main reason for not using Rust. Thankfully, the Rust Language Server is here now and it gets smarter and
more capable every day.
Differences spotted in "Utilities for formatting and printing `String`s\n\nThis module contains the runtime support for the [`format!`] syntax extension.\nThis macro is implemented in the compiler to emit calls to this module in\norder to format arguments at runtime into strings.\n\n# Usage\n\nThe [`format!`] macro is intended to be familiar to those coming from C\'s\n`printf`/`fprintf` functions or Python\'s `str.format` function.\n\nSome examples of the [`format!`] extension are:\n\n```\nformat!(\"Hello\"); // => \"Hello\"\nformat!(\"Hello, {}!\", \"world\"); // => \"Hello, world!\"\nformat!(\"The number is {}\", 1); // => \"The number is 1\"\nformat!(\"{:?}\", (3, 4)); // => \"(3, 4)\"\nformat!(\"{value}\", value=4); // => \"4\"\nformat!(\"{} {}\", 1, 2); // => \"1 2\"\nformat!(\"{:04}\", 42); // => \"0042\" with leading zeros\n```\n\nFrom these, you can see that the first argument is a format string. It is\nrequired by the compiler for this to be a s