repo stringlengths 6 65 | file_url stringlengths 81 311 | file_path stringlengths 6 227 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:31:58 2026-01-04 20:25:31 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/logger.rs | crates/core/logger.rs | /*!
Defines a super simple logger that works with the `log` crate.
We don't do anything fancy. We just need basic log levels and the ability to
print to stderr. We therefore avoid bringing in extra dependencies just for
this functionality.
*/
use log::Log;
/// The simplest possible logger that logs to stderr.
///
//... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/haystack.rs | crates/core/haystack.rs | /*!
Defines a builder for haystacks.
A "haystack" represents something we want to search. It encapsulates the logic
for whether a haystack ought to be searched or not, separate from the standard
ignore rules and other filtering logic.
Effectively, a haystack wraps a directory entry and adds some light application
lev... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/search.rs | crates/core/search.rs | /*!
Defines a very high level "search worker" abstraction.
A search worker manages the high level interaction points between the matcher
(i.e., which regex engine is used), the searcher (i.e., how data is actually
read and matched using the regex engine) and the printer. For example, the
search worker is where things ... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/main.rs | crates/core/main.rs | /*!
The main entry point into ripgrep.
*/
use std::{io::Write, process::ExitCode};
use ignore::WalkState;
use crate::flags::{HiArgs, SearchMode};
#[macro_use]
mod messages;
mod flags;
mod haystack;
mod logger;
mod search;
// Since Rust no longer uses jemalloc by default, ripgrep will, by default,
// use the syste... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/config.rs | crates/core/flags/config.rs | /*!
This module provides routines for reading ripgrep config "rc" files.
The primary output of these routines is a sequence of arguments, where each
argument corresponds precisely to one shell argument.
*/
use std::{
ffi::OsString,
path::{Path, PathBuf},
};
use bstr::{ByteSlice, io::BufReadExt};
/// Return ... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/parse.rs | crates/core/flags/parse.rs | /*!
Parses command line arguments into a structured and typed representation.
*/
use std::{borrow::Cow, collections::BTreeSet, ffi::OsString};
use anyhow::Context;
use crate::flags::{
Flag, FlagValue,
defs::FLAGS,
hiargs::HiArgs,
lowargs::{LoggingMode, LowArgs, SpecialMode},
};
/// The result of par... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/defs.rs | crates/core/flags/defs.rs | /*!
Defines all of the flags available in ripgrep.
Each flag corresponds to a unit struct with a corresponding implementation
of `Flag`. Note that each implementation of `Flag` might actually have many
possible manifestations of the same "flag." That is, each implementation of
`Flag` can have the following flags avail... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | true |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/mod.rs | crates/core/flags/mod.rs | /*!
Defines ripgrep's command line interface.
This modules deals with everything involving ripgrep's flags and positional
arguments. This includes generating shell completions, `--help` output and even
ripgrep's man page. It's also responsible for parsing and validating every
flag (including reading ripgrep's config f... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/lowargs.rs | crates/core/flags/lowargs.rs | /*!
Provides the definition of low level arguments from CLI flags.
*/
use std::{
ffi::{OsStr, OsString},
path::PathBuf,
};
use {
bstr::{BString, ByteVec},
grep::printer::{HyperlinkFormat, UserColorSpec},
};
/// A collection of "low level" arguments.
///
/// The "low level" here is meant to constrain ... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/hiargs.rs | crates/core/flags/hiargs.rs | /*!
Provides the definition of high level arguments from CLI flags.
*/
use std::{
collections::HashSet,
path::{Path, PathBuf},
};
use {
bstr::BString,
grep::printer::{ColorSpecs, SummaryKind},
};
use crate::{
flags::lowargs::{
BinaryMode, BoundaryMode, BufferMode, CaseMode, ColorChoice,
... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | true |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/complete/bash.rs | crates/core/flags/complete/bash.rs | /*!
Provides completions for ripgrep's CLI for the bash shell.
*/
use crate::flags::defs::FLAGS;
const TEMPLATE_FULL: &'static str = "
_rg() {
local i cur prev opts cmds
COMPREPLY=()
cur=\"${COMP_WORDS[COMP_CWORD]}\"
prev=\"${COMP_WORDS[COMP_CWORD-1]}\"
cmd=\"\"
opts=\"\"
for i in ${COMP_WORDS[@]}; do
... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/complete/zsh.rs | crates/core/flags/complete/zsh.rs | /*!
Provides completions for ripgrep's CLI for the zsh shell.
Unlike completion short for other shells (at time of writing), zsh's
completions for ripgrep are maintained by hand. This is because:
1. They are lovingly written by an expert in such things.
2. Are much higher in quality than the ones below that are auto-... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/complete/mod.rs | crates/core/flags/complete/mod.rs | /*!
Modules for generating completions for various shells.
*/
static ENCODINGS: &'static str = include_str!("encodings.sh");
pub(super) mod bash;
pub(super) mod fish;
pub(super) mod powershell;
pub(super) mod zsh;
| rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/complete/fish.rs | crates/core/flags/complete/fish.rs | /*!
Provides completions for ripgrep's CLI for the fish shell.
*/
use crate::flags::{CompletionType, defs::FLAGS};
const TEMPLATE: &'static str = "complete -c rg !SHORT! -l !LONG! -d '!DOC!'";
const TEMPLATE_NEGATED: &'static str = "complete -c rg -l !NEGATED! -n '__rg_contains_opt !LONG! !SHORT!' -d '!DOC!'\n";
///... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/complete/powershell.rs | crates/core/flags/complete/powershell.rs | /*!
Provides completions for ripgrep's CLI for PowerShell.
*/
use crate::flags::defs::FLAGS;
const TEMPLATE: &'static str = "
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
Register-ArgumentCompleter -Native -CommandName 'rg' -ScriptBlock {
param($wordToComplete,... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/doc/version.rs | crates/core/flags/doc/version.rs | /*!
Provides routines for generating version strings.
Version strings can be just the digits, an overall short one-line description
or something more verbose that includes things like CPU target feature support.
*/
use std::fmt::Write;
/// Generates just the numerical part of the version of ripgrep.
///
/// This inc... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/doc/man.rs | crates/core/flags/doc/man.rs | /*!
Provides routines for generating ripgrep's man page in `roff` format.
*/
use std::{collections::BTreeMap, fmt::Write};
use crate::flags::{Flag, defs::FLAGS, doc::version};
const TEMPLATE: &'static str = include_str!("template.rg.1");
/// Wraps `std::write!` and asserts there is no failure.
///
/// We only write... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/doc/help.rs | crates/core/flags/doc/help.rs | /*!
Provides routines for generating ripgrep's "short" and "long" help
documentation.
The short version is used when the `-h` flag is given, while the long version
is used when the `--help` flag is given.
*/
use std::{collections::BTreeMap, fmt::Write};
use crate::flags::{Category, Flag, defs::FLAGS, doc::version};
... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/doc/mod.rs | crates/core/flags/doc/mod.rs | /*!
Modules for generating documentation for ripgrep's flags.
*/
pub(crate) mod help;
pub(crate) mod man;
pub(crate) mod version;
/// Searches for `\tag{...}` occurrences in `doc` and calls `replacement` for
/// each such tag found.
///
/// The first argument given to `replacement` is the tag value, `...`. The
/// se... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/cli/src/lib.rs | crates/cli/src/lib.rs | /*!
This crate provides common routines used in command line applications, with a
focus on routines useful for search oriented applications. As a utility
library, there is no central type or function. However, a key focus of this
crate is to improve failure modes and provide user friendly error messages
when things go ... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/cli/src/process.rs | crates/cli/src/process.rs | use std::{
io::{self, Read},
process,
};
/// An error that can occur while running a command and reading its output.
///
/// This error can be seamlessly converted to an `io::Error` via a `From`
/// implementation.
#[derive(Debug)]
pub struct CommandError {
kind: CommandErrorKind,
}
#[derive(Debug)]
enum ... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/cli/src/pattern.rs | crates/cli/src/pattern.rs | use std::{ffi::OsStr, io, path::Path};
use bstr::io::BufReadExt;
use crate::escape::{escape, escape_os};
/// An error that occurs when a pattern could not be converted to valid UTF-8.
///
/// The purpose of this error is to give a more targeted failure mode for
/// patterns written by end users that are not valid UT... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/cli/src/hostname.rs | crates/cli/src/hostname.rs | use std::{ffi::OsString, io};
/// Returns the hostname of the current system.
///
/// It is unusual, although technically possible, for this routine to return
/// an error. It is difficult to list out the error conditions, but one such
/// possibility is platform support.
///
/// # Platform specific behavior
///
/// O... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/cli/src/wtr.rs | crates/cli/src/wtr.rs | use std::io::{self, IsTerminal};
use termcolor::HyperlinkSpec;
/// A writer that supports coloring with either line or block buffering.
#[derive(Debug)]
pub struct StandardStream(StandardStreamKind);
/// Returns a possibly buffered writer to stdout for the given color choice.
///
/// The writer returned is either li... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/cli/src/human.rs | crates/cli/src/human.rs | /// An error that occurs when parsing a human readable size description.
///
/// This error provides an end user friendly message describing why the
/// description couldn't be parsed and what the expected format is.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ParseSizeError {
original: String,
kind: Pars... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/cli/src/decompress.rs | crates/cli/src/decompress.rs | use std::{
ffi::{OsStr, OsString},
fs::File,
io,
path::{Path, PathBuf},
process::Command,
};
use globset::{Glob, GlobSet, GlobSetBuilder};
use crate::process::{CommandError, CommandReader, CommandReaderBuilder};
/// A builder for a matcher that determines which files get decompressed.
#[derive(Cl... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/cli/src/escape.rs | crates/cli/src/escape.rs | use std::ffi::OsStr;
use bstr::{ByteSlice, ByteVec};
/// Escapes arbitrary bytes into a human readable string.
///
/// This converts `\t`, `\r` and `\n` into their escaped forms. It also
/// converts the non-printable subset of ASCII in addition to invalid UTF-8
/// bytes to hexadecimal escape sequences. Everything e... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/globset/src/serde_impl.rs | crates/globset/src/serde_impl.rs | use serde::{
de::{Error, SeqAccess, Visitor},
{Deserialize, Deserializer, Serialize, Serializer},
};
use crate::{Glob, GlobSet, GlobSetBuilder};
impl Serialize for Glob {
fn serialize<S: Serializer>(
&self,
serializer: S,
) -> Result<S::Ok, S::Error> {
serializer.serialize_str(... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/globset/src/lib.rs | crates/globset/src/lib.rs | /*!
The globset crate provides cross platform single glob and glob set matching.
Glob set matching is the process of matching one or more glob patterns against
a single candidate path simultaneously, and returning all of the globs that
matched. For example, given this set of globs:
* `*.rs`
* `src/lib.rs`
* `src/**/f... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | true |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/globset/src/pathutil.rs | crates/globset/src/pathutil.rs | use std::borrow::Cow;
use bstr::{ByteSlice, ByteVec};
/// The final component of the path, if it is a normal file.
///
/// If the path terminates in `..`, or consists solely of a root of prefix,
/// file_name will return `None`.
pub(crate) fn file_name<'a>(path: &Cow<'a, [u8]>) -> Option<Cow<'a, [u8]>> {
if path.... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/globset/src/glob.rs | crates/globset/src/glob.rs | use std::fmt::Write;
use std::path::{Path, is_separator};
use regex_automata::meta::Regex;
use crate::{Candidate, Error, ErrorKind, new_regex};
/// Describes a matching strategy for a particular pattern.
///
/// This provides a way to more quickly determine whether a pattern matches
/// a particular file path in a w... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | true |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/globset/src/fnv.rs | crates/globset/src/fnv.rs | /// A convenience alias for creating a hash map with an FNV hasher.
pub(crate) type HashMap<K, V> =
std::collections::HashMap<K, V, std::hash::BuildHasherDefault<Hasher>>;
/// A hasher that implements the Fowler–Noll–Vo (FNV) hash.
pub(crate) struct Hasher(u64);
impl Hasher {
const OFFSET_BASIS: u64 = 0xcbf29... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/globset/benches/bench.rs | crates/globset/benches/bench.rs | /*!
This module benchmarks the glob implementation. For benchmarks on the ripgrep
tool itself, see the benchsuite directory.
*/
#![feature(test)]
extern crate test;
use globset::{Candidate, Glob, GlobMatcher, GlobSet, GlobSetBuilder};
const EXT: &'static str = "some/a/bigger/path/to/the/crazy/needle.txt";
const EXT_... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/printer/src/stats.rs | crates/printer/src/stats.rs | use std::{
ops::{Add, AddAssign},
time::Duration,
};
use crate::util::NiceDuration;
/// Summary statistics produced at the end of a search.
///
/// When statistics are reported by a printer, they correspond to all searches
/// executed with that printer.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub str... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/printer/src/path.rs | crates/printer/src/path.rs | use std::{io, path::Path};
use termcolor::WriteColor;
use crate::{
color::ColorSpecs,
hyperlink::{self, HyperlinkConfig},
util::PrinterPath,
};
/// A configuration for describing how paths should be written.
#[derive(Clone, Debug)]
struct Config {
colors: ColorSpecs,
hyperlink: HyperlinkConfig,
... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/printer/src/lib.rs | crates/printer/src/lib.rs | /*!
This crate provides featureful and fast printers that interoperate with the
[`grep-searcher`](https://docs.rs/grep-searcher)
crate.
# Brief overview
The [`Standard`] printer shows results in a human readable format, and is
modeled after the formats used by standard grep-like tools. Features include,
but are not l... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/printer/src/standard.rs | crates/printer/src/standard.rs | use std::{
cell::{Cell, RefCell},
cmp,
io::{self, Write},
path::Path,
sync::Arc,
time::Instant,
};
use {
bstr::ByteSlice,
grep_matcher::{Match, Matcher},
grep_searcher::{
LineStep, Searcher, Sink, SinkContext, SinkFinish, SinkMatch,
},
termcolor::{ColorSpec, NoColor,... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | true |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/printer/src/json.rs | crates/printer/src/json.rs | use std::{
io::{self, Write},
path::Path,
sync::Arc,
time::Instant,
};
use {
grep_matcher::{Match, Matcher},
grep_searcher::{Searcher, Sink, SinkContext, SinkFinish, SinkMatch},
serde_json as json,
};
use crate::{
counter::CounterWriter, jsont, stats::Stats, util::Replacer,
util::f... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | true |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/printer/src/jsont.rs | crates/printer/src/jsont.rs | // This module defines the types we use for JSON serialization. We specifically
// omit deserialization, partially because there isn't a clear use case for
// them at this time, but also because deserialization will complicate things.
// Namely, the types below are designed in a way that permits JSON
// serialization w... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/printer/src/util.rs | crates/printer/src/util.rs | use std::{borrow::Cow, cell::OnceCell, fmt, io, path::Path, time};
use {
bstr::ByteVec,
grep_matcher::{Captures, LineTerminator, Match, Matcher},
grep_searcher::{
LineIter, Searcher, SinkContext, SinkContextKind, SinkError, SinkMatch,
},
};
use crate::{MAX_LOOK_AHEAD, hyperlink::HyperlinkPath}... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/printer/src/summary.rs | crates/printer/src/summary.rs | use std::{
cell::RefCell,
io::{self, Write},
path::Path,
sync::Arc,
time::Instant,
};
use {
grep_matcher::Matcher,
grep_searcher::{Searcher, Sink, SinkError, SinkFinish, SinkMatch},
termcolor::{ColorSpec, NoColor, WriteColor},
};
use crate::{
color::ColorSpecs,
counter::Counter... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | true |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/printer/src/macros.rs | crates/printer/src/macros.rs | /// Like assert_eq, but nicer output for long strings.
#[cfg(test)]
#[macro_export]
macro_rules! assert_eq_printed {
($expected:expr, $got:expr) => {
let expected = &*$expected;
let got = &*$got;
if expected != got {
panic!("
printed outputs differ!
expected:
~~~~~~~~~~~~~~~~~~~... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/printer/src/counter.rs | crates/printer/src/counter.rs | use std::io::{self, Write};
use termcolor::{ColorSpec, HyperlinkSpec, WriteColor};
/// A writer that counts the number of bytes that have been successfully
/// written.
#[derive(Clone, Debug)]
pub(crate) struct CounterWriter<W> {
wtr: W,
count: u64,
total_count: u64,
}
impl<W: Write> CounterWriter<W> {
... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/printer/src/color.rs | crates/printer/src/color.rs | use termcolor::{Color, ColorSpec, ParseColorError};
/// Returns a default set of color specifications.
///
/// This may change over time, but the color choices are meant to be fairly
/// conservative that work across terminal themes.
///
/// Additional color specifications can be added to the list returned. More
/// r... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/printer/src/hyperlink/mod.rs | crates/printer/src/hyperlink/mod.rs | use std::{cell::RefCell, io, path::Path, sync::Arc};
use {
bstr::ByteSlice,
termcolor::{HyperlinkSpec, WriteColor},
};
use crate::util::DecimalFormatter;
use self::aliases::HYPERLINK_PATTERN_ALIASES;
mod aliases;
/// Hyperlink configuration.
///
/// This configuration specifies both the [hyperlink format](... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | true |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/printer/src/hyperlink/aliases.rs | crates/printer/src/hyperlink/aliases.rs | use crate::hyperlink::HyperlinkAlias;
/// Aliases to well-known hyperlink schemes.
///
/// These need to be sorted by name.
pub(super) const HYPERLINK_PATTERN_ALIASES: &[HyperlinkAlias] = &[
alias(
"cursor",
"Cursor scheme (cursor://)",
"cursor://file{path}:{line}:{column}",
),
prio... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/pcre2/src/lib.rs | crates/pcre2/src/lib.rs | /*!
An implementation of `grep-matcher`'s `Matcher` trait for
[PCRE2](https://www.pcre.org/).
*/
#![deny(missing_docs)]
pub use pcre2::{is_jit_available, version};
pub use crate::{
error::{Error, ErrorKind},
matcher::{RegexCaptures, RegexMatcher, RegexMatcherBuilder},
};
mod error;
mod matcher;
| rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/pcre2/src/error.rs | crates/pcre2/src/error.rs | /// An error that can occur in this crate.
///
/// Generally, this error corresponds to problems building a regular
/// expression, whether it's in parsing, compilation or a problem with
/// guaranteeing a configured optimization.
#[derive(Clone, Debug)]
pub struct Error {
kind: ErrorKind,
}
impl Error {
pub(c... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
BurntSushi/ripgrep | https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/pcre2/src/matcher.rs | crates/pcre2/src/matcher.rs | use std::collections::HashMap;
use {
grep_matcher::{Captures, Match, Matcher},
pcre2::bytes::{CaptureLocations, Regex, RegexBuilder},
};
use crate::error::Error;
/// A builder for configuring the compilation of a PCRE2 regex.
#[derive(Clone, Debug)]
pub struct RegexMatcherBuilder {
builder: RegexBuilder,... | rust | Unlicense | 0a88cccd5188074de96f54a4b6b44a63971ac157 | 2026-01-04T15:31:58.730867Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/build.rs | build.rs | fn main() {
// Fix building from source on Windows because it can't handle file links.
#[cfg(windows)]
let _ = std::fs::copy("dev/Cargo.toml", "dev-Cargo.toml");
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/19_smart_pointers/cow1.rs | solutions/19_smart_pointers/cow1.rs | // This exercise explores the `Cow` (Clone-On-Write) smart pointer. It can
// enclose and provide immutable access to borrowed data and clone the data
// lazily when mutation or ownership is required. The type is designed to work
// with general borrowed data via the `Borrow` trait.
use std::borrow::Cow;
fn abs_all(i... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/19_smart_pointers/box1.rs | solutions/19_smart_pointers/box1.rs | // At compile time, Rust needs to know how much space a type takes up. This
// becomes problematic for recursive types, where a value can have as part of
// itself another value of the same type. To get around the issue, we can use a
// `Box` - a smart pointer used to store data on the heap, which also allows us
// to ... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/19_smart_pointers/arc1.rs | solutions/19_smart_pointers/arc1.rs | // In this exercise, we are given a `Vec` of `u32` called `numbers` with values
// ranging from 0 to 99. We would like to use this set of numbers within 8
// different threads simultaneously. Each thread is going to get the sum of
// every eighth value with an offset.
//
// The first thread (offset 0), will sum 0, 8, 1... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/19_smart_pointers/rc1.rs | solutions/19_smart_pointers/rc1.rs | // In this exercise, we want to express the concept of multiple owners via the
// `Rc<T>` type. This is a model of our solar system - there is a `Sun` type and
// multiple `Planet`s. The planets take ownership of the sun, indicating that
// they revolve around the sun.
use std::rc::Rc;
#[derive(Debug)]
struct Sun;
#... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/22_clippy/clippy1.rs | solutions/22_clippy/clippy1.rs | // The Clippy tool is a collection of lints to analyze your code so you can
// catch common mistakes and improve your Rust code.
//
// For these exercises, the code will fail to compile when there are Clippy
// warnings. Check Clippy's suggestions from the output to solve the exercise.
use std::f32::consts::PI;
fn ma... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/22_clippy/clippy3.rs | solutions/22_clippy/clippy3.rs | use std::mem;
#[allow(unused_variables, unused_assignments)]
fn main() {
let my_option: Option<&str> = None;
// `unwrap` of an `Option` after checking if it is `None` will panic.
// Use `if-let` instead.
if let Some(value) = my_option {
println!("{value}");
}
// A comma was missing.
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/22_clippy/clippy2.rs | solutions/22_clippy/clippy2.rs | fn main() {
let mut res = 42;
let option = Some(12);
// Use `if-let` instead of iteration.
if let Some(x) = option {
res += x;
}
println!("{res}");
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/09_strings/strings1.rs | solutions/09_strings/strings1.rs | fn current_favorite_color() -> String {
// Equivalent to `String::from("blue")`
"blue".to_string()
}
fn main() {
let answer = current_favorite_color();
println!("My current favorite color is {answer}");
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/09_strings/strings2.rs | solutions/09_strings/strings2.rs | fn is_a_color_word(attempt: &str) -> bool {
attempt == "green" || attempt == "blue" || attempt == "red"
}
fn main() {
let word = String::from("green");
if is_a_color_word(&word) {
// ^ added to have `&String` which is automatically
// coerced to `&str` by the comp... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/09_strings/strings3.rs | solutions/09_strings/strings3.rs | fn trim_me(input: &str) -> &str {
input.trim()
}
fn compose_me(input: &str) -> String {
// The macro `format!` has the same syntax as `println!`, but it returns a
// string instead of printing it to the terminal.
// Equivalent to `input.to_string() + " world!"`
format!("{input} world!")
}
fn repla... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/09_strings/strings4.rs | solutions/09_strings/strings4.rs | fn string_slice(arg: &str) {
println!("{arg}");
}
fn string(arg: String) {
println!("{arg}");
}
fn main() {
string_slice("blue");
string("red".to_string());
string(String::from("hi"));
string("rust is fun!".to_owned());
// Here, both answers work.
// `.into()` converts a type into ... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/20_threads/threads3.rs | solutions/20_threads/threads3.rs | use std::{sync::mpsc, thread, time::Duration};
struct Queue {
first_half: Vec<u32>,
second_half: Vec<u32>,
}
impl Queue {
fn new() -> Self {
Self {
first_half: vec![1, 2, 3, 4, 5],
second_half: vec![6, 7, 8, 9, 10],
}
}
}
fn send_tx(q: Queue, tx: mpsc::Sender<u... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/20_threads/threads2.rs | solutions/20_threads/threads2.rs | // Building on the last exercise, we want all of the threads to complete their
// work. But this time, the spawned threads need to be in charge of updating a
// shared value: `JobStatus.jobs_done`
use std::{
sync::{Arc, Mutex},
thread,
time::Duration,
};
struct JobStatus {
jobs_done: u32,
}
fn main()... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/20_threads/threads1.rs | solutions/20_threads/threads1.rs | // This program spawns multiple threads that each runs for at least 250ms, and
// each thread returns how much time it took to complete. The program should
// wait until all the spawned threads have finished and should collect their
// return values into a vector.
use std::{
thread,
time::{Duration, Instant},
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/13_error_handling/errors2.rs | solutions/13_error_handling/errors2.rs | // Say we're writing a game where you can buy items with tokens. All items cost
// 5 tokens, and whenever you purchase items there is a processing fee of 1
// token. A player of the game will type in how many items they want to buy, and
// the `total_cost` function will calculate the total cost of the items. Since
// t... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/13_error_handling/errors6.rs | solutions/13_error_handling/errors6.rs | // Using catch-all error types like `Box<dyn Error>` isn't recommended for
// library code where callers might want to make decisions based on the error
// content instead of printing it out or propagating it further. Here, we define
// a custom error type to make it possible for callers to decide what to do next
// wh... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/13_error_handling/errors3.rs | solutions/13_error_handling/errors3.rs | // This is a program that is trying to use a completed version of the
// `total_cost` function from the previous exercise. It's not working though!
// Why not? What should we do to fix it?
use std::num::ParseIntError;
// Don't change this function.
fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/13_error_handling/errors1.rs | solutions/13_error_handling/errors1.rs | fn generate_nametag_text(name: String) -> Result<String, String> {
// ^^^^^^ ^^^^^^
if name.is_empty() {
// `Err(String)` instead of `None`.
Err("Empty names aren't allowed".to_string())
} else {
// `Ok` instead of `Some`.
Ok(format!... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/13_error_handling/errors4.rs | solutions/13_error_handling/errors4.rs | use std::cmp::Ordering;
#[derive(PartialEq, Debug)]
enum CreationError {
Negative,
Zero,
}
#[derive(PartialEq, Debug)]
struct PositiveNonzeroInteger(u64);
impl PositiveNonzeroInteger {
fn new(value: i64) -> Result<Self, CreationError> {
match value.cmp(&0) {
Ordering::Less => Err(Crea... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/13_error_handling/errors5.rs | solutions/13_error_handling/errors5.rs | // This exercise is an altered version of the `errors4` exercise. It uses some
// concepts that we won't get to until later in the course, like `Box` and the
// `From` trait. It's not important to understand them in detail right now, but
// you can read ahead if you like. For now, think of the `Box<dyn ???>` type as
//... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/23_conversions/from_str.rs | solutions/23_conversions/from_str.rs | // This is similar to the previous `from_into` exercise. But this time, we'll
// implement `FromStr` and return errors instead of falling back to a default
// value. Additionally, upon implementing `FromStr`, you can use the `parse`
// method on strings to generate an object of the implementor type. You can read
// mor... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/23_conversions/try_from_into.rs | solutions/23_conversions/try_from_into.rs | // `TryFrom` is a simple and safe type conversion that may fail in a controlled
// way under some circumstances. Basically, this is the same as `From`. The main
// difference is that this should return a `Result` type instead of the target
// type itself. You can read more about it in the documentation:
// https://doc.... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/23_conversions/using_as.rs | solutions/23_conversions/using_as.rs | // Type casting in Rust is done via the usage of the `as` operator.
// Note that the `as` operator is not only used when type casting. It also helps
// with renaming imports.
fn average(values: &[f64]) -> f64 {
let total = values.iter().sum::<f64>();
total / values.len() as f64
// ^^^^^^
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/23_conversions/from_into.rs | solutions/23_conversions/from_into.rs | // The `From` trait is used for value-to-value conversions. If `From` is
// implemented, an implementation of `Into` is automatically provided.
// You can read more about it in the documentation:
// https://doc.rust-lang.org/std/convert/trait.From.html
#[derive(Debug)]
struct Person {
name: String,
age: u8,
}
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/23_conversions/as_ref_mut.rs | solutions/23_conversions/as_ref_mut.rs | // AsRef and AsMut allow for cheap reference-to-reference conversions. Read more
// about them at https://doc.rust-lang.org/std/convert/trait.AsRef.html and
// https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively.
// Obtain the number of bytes (not characters) in the given argument
// (`.len()` returns... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/07_structs/structs1.rs | solutions/07_structs/structs1.rs | struct ColorRegularStruct {
red: u8,
green: u8,
blue: u8,
}
struct ColorTupleStruct(u8, u8, u8);
#[derive(Debug)]
struct UnitStruct;
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn regular_structs() {
let green = ColorRegula... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/07_structs/structs2.rs | solutions/07_structs/structs2.rs | #[derive(Debug)]
struct Order {
name: String,
year: u32,
made_by_phone: bool,
made_by_mobile: bool,
made_by_email: bool,
item_number: u32,
count: u32,
}
fn create_order_template() -> Order {
Order {
name: String::from("Bob"),
year: 2019,
made_by_phone: false,
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/07_structs/structs3.rs | solutions/07_structs/structs3.rs | #[derive(Debug)]
struct Package {
sender_country: String,
recipient_country: String,
weight_in_grams: u32,
}
impl Package {
fn new(sender_country: String, recipient_country: String, weight_in_grams: u32) -> Self {
if weight_in_grams < 10 {
// This isn't how you should handle errors ... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/17_tests/tests1.rs | solutions/17_tests/tests1.rs | // Tests are important to ensure that your code does what you think it should
// do.
fn is_even(n: i64) -> bool {
n % 2 == 0
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
// When writing unit tests, it is common to import everything from the outer
// module (`super`)... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/17_tests/tests2.rs | solutions/17_tests/tests2.rs | // Calculates the power of 2 using a bit shift.
// `1 << n` is equivalent to "2 to the power of n".
fn power_of_2(n: u8) -> u64 {
1 << n
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn you_can_assert_eq() {
assert_eq!(power_of_2(0),... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/17_tests/tests3.rs | solutions/17_tests/tests3.rs | struct Rectangle {
width: i32,
height: i32,
}
impl Rectangle {
// Don't change this function.
fn new(width: i32, height: i32) -> Self {
if width <= 0 || height <= 0 {
// Returning a `Result` would be better here. But we want to learn
// how to test functions that can pan... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/15_traits/traits3.rs | solutions/15_traits/traits3.rs | trait Licensed {
fn licensing_info(&self) -> String {
"Default license".to_string()
}
}
struct SomeSoftware {
version_number: i32,
}
struct OtherSoftware {
version_number: String,
}
impl Licensed for SomeSoftware {}
impl Licensed for OtherSoftware {}
fn main() {
// You can optionally exp... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/15_traits/traits4.rs | solutions/15_traits/traits4.rs | trait Licensed {
fn licensing_info(&self) -> String {
"Default license".to_string()
}
}
struct SomeSoftware;
struct OtherSoftware;
impl Licensed for SomeSoftware {}
impl Licensed for OtherSoftware {}
fn compare_license_types(software1: impl Licensed, software2: impl Licensed) -> bool {
// ... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/15_traits/traits1.rs | solutions/15_traits/traits1.rs | // The trait `AppendBar` has only one function which appends "Bar" to any object
// implementing this trait.
trait AppendBar {
fn append_bar(self) -> Self;
}
impl AppendBar for String {
fn append_bar(self) -> Self {
self + "Bar"
}
}
fn main() {
let s = String::from("Foo");
let s = s.append... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/15_traits/traits5.rs | solutions/15_traits/traits5.rs | trait SomeTrait {
fn some_function(&self) -> bool {
true
}
}
trait OtherTrait {
fn other_function(&self) -> bool {
true
}
}
struct SomeStruct;
impl SomeTrait for SomeStruct {}
impl OtherTrait for SomeStruct {}
struct OtherStruct;
impl SomeTrait for OtherStruct {}
impl OtherTrait for O... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/15_traits/traits2.rs | solutions/15_traits/traits2.rs | trait AppendBar {
fn append_bar(self) -> Self;
}
impl AppendBar for Vec<String> {
fn append_bar(mut self) -> Self {
// ^^^ this is important
self.push(String::from("Bar"));
self
}
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use su... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/11_hashmaps/hashmaps3.rs | solutions/11_hashmaps/hashmaps3.rs | // A list of scores (one per line) of a soccer match is given. Each line is of
// the form "<team_1_name>,<team_2_name>,<team_1_goals>,<team_2_goals>"
// Example: "England,France,4,2" (England scored 4 goals, France 2).
//
// You have to build a scores table containing the name of the team, the total
// number of goals... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/11_hashmaps/hashmaps2.rs | solutions/11_hashmaps/hashmaps2.rs | // We're collecting different fruits to bake a delicious fruit cake. For this,
// we have a basket, which we'll represent in the form of a hash map. The key
// represents the name of each fruit we collect and the value represents how
// many of that particular fruit we have collected. Three types of fruits -
// Apple (... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/11_hashmaps/hashmaps1.rs | solutions/11_hashmaps/hashmaps1.rs | // A basket of fruits in the form of a hash map needs to be defined. The key
// represents the name of the fruit and the value represents how many of that
// particular fruit is in the basket. You have to put at least 3 different
// types of fruits (e.g. apple, banana, mango) in the basket and the total count
// of all... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/08_enums/enums2.rs | solutions/08_enums/enums2.rs | #[derive(Debug)]
struct Point {
x: u64,
y: u64,
}
#[derive(Debug)]
enum Message {
Resize { width: u64, height: u64 },
Move(Point),
Echo(String),
ChangeColor(u8, u8, u8),
Quit,
}
impl Message {
fn call(&self) {
println!("{self:?}");
}
}
fn main() {
let messages = [
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/08_enums/enums1.rs | solutions/08_enums/enums1.rs | #[derive(Debug)]
enum Message {
Resize,
Move,
Echo,
ChangeColor,
Quit,
}
fn main() {
println!("{:?}", Message::Resize);
println!("{:?}", Message::Move);
println!("{:?}", Message::Echo);
println!("{:?}", Message::ChangeColor);
println!("{:?}", Message::Quit);
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/08_enums/enums3.rs | solutions/08_enums/enums3.rs | struct Point {
x: u64,
y: u64,
}
enum Message {
Resize { width: u64, height: u64 },
Move(Point),
Echo(String),
ChangeColor(u8, u8, u8),
Quit,
}
struct State {
width: u64,
height: u64,
position: Point,
message: String,
color: (u8, u8, u8),
quit: bool,
}
impl State {... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/18_iterators/iterators1.rs | solutions/18_iterators/iterators1.rs | // When performing operations on elements within a collection, iterators are
// essential. This module helps you get familiar with the structure of using an
// iterator and how to go through elements within an iterable collection.
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
#... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/18_iterators/iterators4.rs | solutions/18_iterators/iterators4.rs | // 3 possible solutions are presented.
// With `for` loop and a mutable variable.
fn factorial_for(num: u64) -> u64 {
let mut result = 1;
for x in 2..=num {
result *= x;
}
result
}
// Equivalent to `factorial_for` but shorter and without a `for` loop and
// mutable variables.
fn factorial_fo... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/18_iterators/iterators3.rs | solutions/18_iterators/iterators3.rs | #[derive(Debug, PartialEq, Eq)]
enum DivisionError {
// Example: 42 / 0
DivideByZero,
// Only case for `i64`: `i64::MIN / -1` because the result is `i64::MAX + 1`
IntegerOverflow,
// Example: 5 / 2 = 2.5
NotDivisible,
}
fn divide(a: i64, b: i64) -> Result<i64, DivisionError> {
if b == 0 {
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/18_iterators/iterators2.rs | solutions/18_iterators/iterators2.rs | // In this exercise, you'll learn some of the unique advantages that iterators
// can offer.
// "hello" -> "Hello"
fn capitalize_first(input: &str) -> String {
let mut chars = input.chars();
match chars.next() {
None => String::new(),
Some(first) => first.to_uppercase().to_string() + chars.as_s... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/18_iterators/iterators5.rs | solutions/18_iterators/iterators5.rs | // Let's define a simple model to track Rustlings' exercise progress. Progress
// will be modelled using a hash map. The name of the exercise is the key and
// the progress is the value. Two counting functions were created to count the
// number of exercises with a given progress. Recreate this counting
// functionalit... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/03_if/if1.rs | solutions/03_if/if1.rs | fn bigger(a: i32, b: i32) -> i32 {
if a > b { a } else { b }
}
fn main() {
// You can optionally experiment here.
}
// Don't mind this for now :)
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ten_is_bigger_than_eight() {
assert_eq!(10, bigger(10, 8));
}
#[test]
fn fortytw... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/03_if/if3.rs | solutions/03_if/if3.rs | fn animal_habitat(animal: &str) -> &str {
let identifier = if animal == "crab" {
1
} else if animal == "gopher" {
2
} else if animal == "snake" {
3
} else {
// Any unused identifier.
4
};
// Instead of such an identifier, you would use an enum in Rust.
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/solutions/03_if/if2.rs | solutions/03_if/if2.rs | fn picky_eater(food: &str) -> &str {
if food == "strawberry" {
"Yummy!"
} else if food == "potato" {
"I guess I can eat that."
} else {
"No thanks!"
}
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn yummy... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.