Skip to content

Instantly share code, notes, and snippets.

@hjr3
Created October 20, 2016 14:28
Show Gist options
  • Save hjr3/94f15b5f3995d78a79f37eab7165797e to your computer and use it in GitHub Desktop.
Save hjr3/94f15b5f3995d78a79f37eab7165797e to your computer and use it in GitHub Desktop.
Rust Naming Conventions
Convention Example General Meaning
to_*() str::to_string() A conversion from one type to another that may have an allocation or computation cost. Usually a Borrowed type to Owned type.
as_*() String::as_str() Convert an Owned type into a Borrowed type. It is usually cheap (maybe even zero-cost) to use this function.
into_*() String::into_bytes() Consume a type T and convert it into an Owned type U.
from_*() SocketAddr::from_str() Create an Owned type from an Owned or Borrowed type.
*_mut() str::split_at_mut() Denotes a mutable reference.
try_*() usize::try_from() Method will return a Result or Option type. Usually Result.
with_*() Vec::with_capacity() A constructor that has one or more parameters used to configure the type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment