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 |
|---|---|---|---|---|---|---|---|---|
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/17_tests/tests2.rs | exercises/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() {
// TODO: Test the functio... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/17_tests/tests3.rs | exercises/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/exercises/15_traits/traits3.rs | exercises/15_traits/traits3.rs | trait Licensed {
// TODO: Add a default implementation for `licensing_info` so that
// implementors like the two structs below can share that default behavior
// without repeating the function.
// The default license information should be the string "Default license".
fn licensing_info(&self) -> Str... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/15_traits/traits4.rs | exercises/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 {}
// TODO: Fix the compiler error by only changing the signature of this function.
fn compare_license_t... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/15_traits/traits1.rs | exercises/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 {
// TODO: Implement `AppendBar` for the type `String`.
}
fn main() {
let s = String::from("Foo");
let s = s.append_ba... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/15_traits/traits5.rs | exercises/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/exercises/15_traits/traits2.rs | exercises/15_traits/traits2.rs | trait AppendBar {
fn append_bar(self) -> Self;
}
// TODO: Implement the trait `AppendBar` for a vector of strings.
// `append_bar` should push the string "Bar" into the vector.
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_vec_pop_eq_ba... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/11_hashmaps/hashmaps3.rs | exercises/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/exercises/11_hashmaps/hashmaps2.rs | exercises/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/exercises/11_hashmaps/hashmaps1.rs | exercises/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/exercises/08_enums/enums2.rs | exercises/08_enums/enums2.rs | #[derive(Debug)]
struct Point {
x: u64,
y: u64,
}
#[derive(Debug)]
enum Message {
// TODO: Define the different variants used below.
}
impl Message {
fn call(&self) {
println!("{self:?}");
}
}
fn main() {
let messages = [
Message::Resize {
width: 10,
he... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/08_enums/enums1.rs | exercises/08_enums/enums1.rs | #[derive(Debug)]
enum Message {
// TODO: Define a few types of messages as used below.
}
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/exercises/08_enums/enums3.rs | exercises/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,
// RGB color composed of red, green and blue.
co... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/18_iterators/iterators1.rs | exercises/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/exercises/18_iterators/iterators4.rs | exercises/18_iterators/iterators4.rs | fn factorial(num: u64) -> u64 {
// TODO: Complete this function to return the factorial of `num` which is
// defined as `1 * 2 * 3 * … * num`.
// https://en.wikipedia.org/wiki/Factorial
//
// Do not use:
// - early returns (using the `return` keyword explicitly)
// Try not to use:
// - i... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/18_iterators/iterators3.rs | exercises/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,
}
// TODO: Calculate `a` divided by `b` if `a` is evenly divisible by `b`.
//... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/18_iterators/iterators2.rs | exercises/18_iterators/iterators2.rs | // In this exercise, you'll learn some of the unique advantages that iterators
// can offer.
// TODO: Complete the `capitalize_first` function.
// "hello" -> "Hello"
fn capitalize_first(input: &str) -> String {
let mut chars = input.chars();
match chars.next() {
None => String::new(),
Some(firs... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/18_iterators/iterators5.rs | exercises/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/exercises/03_if/if1.rs | exercises/03_if/if1.rs | fn bigger(a: i32, b: i32) -> i32 {
// TODO: Complete this function to return the bigger number!
// If both numbers are equal, any of them can be returned.
// Do not use:
// - another function call
// - additional variables
}
fn main() {
// You can optionally experiment here.
}
// Don't mind th... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/03_if/if3.rs | exercises/03_if/if3.rs | fn animal_habitat(animal: &str) -> &str {
// TODO: Fix the compiler error in the statement below.
let identifier = if animal == "crab" {
1
} else if animal == "gopher" {
2.0
} else if animal == "snake" {
3
} else {
"Unknown"
};
// Don't change the expression ... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/03_if/if2.rs | exercises/03_if/if2.rs | // TODO: Fix the compiler error on this function.
fn picky_eater(food: &str) -> &str {
if food == "strawberry" {
"Yummy!"
} else {
1
}
}
fn main() {
// You can optionally experiment here.
}
// TODO: Read the tests to understand the desired behavior.
// Make all tests pass without chang... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/05_vecs/vecs1.rs | exercises/05_vecs/vecs1.rs | fn array_and_vec() -> ([i32; 4], Vec<i32>) {
let a = [10, 20, 30, 40]; // Array
// TODO: Create a vector called `v` which contains the exact same elements as in the array `a`.
// Use the vector macro.
// let v = ???;
(a, v)
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/05_vecs/vecs2.rs | exercises/05_vecs/vecs2.rs | fn vec_loop(input: &[i32]) -> Vec<i32> {
let mut output = Vec::new();
for element in input {
// TODO: Multiply each element in the `input` slice by 2 and push it to
// the `output` vector.
}
output
}
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/exercises/14_generics/generics2.rs | exercises/14_generics/generics2.rs | // This powerful wrapper provides the ability to store a positive integer value.
// TODO: Rewrite it using a generic so that it supports wrapping ANY type.
struct Wrapper {
value: u32,
}
// TODO: Adapt the struct's implementation to be generic over the wrapped value.
impl Wrapper {
fn new(value: u32) -> Self {... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/14_generics/generics1.rs | exercises/14_generics/generics1.rs | // `Vec<T>` is generic over the type `T`. In most cases, the compiler is able to
// infer `T`, for example after pushing a value with a concrete type to the vector.
// But in this exercise, the compiler needs some help through a type annotation.
fn main() {
// TODO: Fix the compiler error by annotating the type of... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/10_modules/modules1.rs | exercises/10_modules/modules1.rs | // TODO: Fix the compiler error about calling a private function.
mod sausage_factory {
// Don't let anybody outside of this module see this!
fn get_secret_recipe() -> String {
String::from("Ginger")
}
fn make_sausage() {
get_secret_recipe();
println!("sausage!");
}
}
fn ma... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/10_modules/modules3.rs | exercises/10_modules/modules3.rs | // You can use the `use` keyword to bring module paths from modules from
// anywhere and especially from the standard library into your scope.
// TODO: Bring `SystemTime` and `UNIX_EPOCH` from the `std::time` module into
// your scope. Bonus style points if you can do it with one line!
// use ???;
fn main() {
mat... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/10_modules/modules2.rs | exercises/10_modules/modules2.rs | // You can bring module paths into scopes and provide new names for them with
// the `use` and `as` keywords.
mod delicious_snacks {
// TODO: Add the following two `use` statements after fixing them.
// use self::fruits::PEAR as ???;
// use self::veggies::CUCUMBER as ???;
mod fruits {
pub cons... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/quizzes/quiz2.rs | exercises/quizzes/quiz2.rs | // This is a quiz for the following sections:
// - Strings
// - Vecs
// - Move semantics
// - Modules
// - Enums
//
// Let's build a little machine in the form of a function. As input, we're going
// to give a list of strings and commands. These commands determine what action
// is going to be applied to the string. It... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/quizzes/quiz3.rs | exercises/quizzes/quiz3.rs | // This quiz tests:
// - Generics
// - Traits
//
// An imaginary magical school has a new report card generation system written
// in Rust! Currently, the system only supports creating report cards where the
// student's grade is represented numerically (e.g. 1.0 -> 5.5). However, the
// school also issues alphabetical... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/quizzes/quiz1.rs | exercises/quizzes/quiz1.rs | // This is a quiz for the following sections:
// - Variables
// - Functions
// - If
//
// Mary is buying apples. The price of an apple is calculated as follows:
// - An apple costs 2 rustbucks.
// - However, if Mary buys more than 40 apples, the price of each apple in the
// entire order is reduced to only 1 rustbuck!
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/16_lifetimes/lifetimes1.rs | exercises/16_lifetimes/lifetimes1.rs | // The Rust compiler needs to know how to check whether supplied references are
// valid, so that it can let the programmer know if a reference is at risk of
// going out of scope before it is used. Remember, references are borrows and do
// not own their own data. What if their owner goes out of scope?
// TODO: Fix t... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/16_lifetimes/lifetimes3.rs | exercises/16_lifetimes/lifetimes3.rs | // Lifetimes are also needed when structs hold references.
// TODO: Fix the compiler errors about the struct.
struct Book {
author: &str,
title: &str,
}
fn main() {
let book = Book {
author: "George Orwell",
title: "1984",
};
println!("{} by {}", book.title, book.author);
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/16_lifetimes/lifetimes2.rs | exercises/16_lifetimes/lifetimes2.rs | // Don't change this function.
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() {
x
} else {
y
}
}
fn main() {
// TODO: Fix the compiler error by moving one line.
let string1 = String::from("long string is long");
let result;
{
let string2 = ... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/00_intro/intro1.rs | exercises/00_intro/intro1.rs | // TODO: We sometimes encourage you to keep trying things on a given exercise
// even after you already figured it out. If you got everything working and feel
// ready for the next exercise, enter `n` in the terminal.
//
// The exercise file will be reloaded when you change one of the lines below!
// Try adding a new `... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/00_intro/intro2.rs | exercises/00_intro/intro2.rs | fn main() {
// TODO: Fix the code to print "Hello world!".
printline!("Hello world!");
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/21_macros/macros4.rs | exercises/21_macros/macros4.rs | // TODO: Fix the compiler error by adding one or two characters.
#[rustfmt::skip]
macro_rules! my_macro {
() => {
println!("Check out my macro!");
}
($val:expr) => {
println!("Look at this other macro: {}", $val);
}
}
fn main() {
my_macro!();
my_macro!(7777);
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/21_macros/macros2.rs | exercises/21_macros/macros2.rs | fn main() {
my_macro!();
}
// TODO: Fix the compiler error by moving the whole definition of this macro.
macro_rules! my_macro {
() => {
println!("Check out my macro!");
};
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/21_macros/macros1.rs | exercises/21_macros/macros1.rs | macro_rules! my_macro {
() => {
println!("Check out my macro!");
};
}
fn main() {
// TODO: Fix the macro call.
my_macro();
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/21_macros/macros3.rs | exercises/21_macros/macros3.rs | // TODO: Fix the compiler error without taking the macro definition out of this
// module.
mod macros {
macro_rules! my_macro {
() => {
println!("Check out my macro!");
};
}
}
fn main() {
my_macro!();
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/01_variables/variables5.rs | exercises/01_variables/variables5.rs | fn main() {
let number = "T-H-R-E-E"; // Don't change this line
println!("Spell a number: {number}");
// TODO: Fix the compiler error by changing the line below without renaming the variable.
number = 3;
println!("Number plus two is: {}", number + 2);
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/01_variables/variables1.rs | exercises/01_variables/variables1.rs | fn main() {
// TODO: Add the missing keyword.
x = 5;
println!("x has the value {x}");
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/01_variables/variables2.rs | exercises/01_variables/variables2.rs | fn main() {
// TODO: Change the line below to fix the compiler error.
let x;
if x == 10 {
println!("x is ten!");
} else {
println!("x is not ten!");
}
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/01_variables/variables6.rs | exercises/01_variables/variables6.rs | // TODO: Change the line below to fix the compiler error.
const NUMBER = 3;
fn main() {
println!("Number: {NUMBER}");
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/01_variables/variables3.rs | exercises/01_variables/variables3.rs | fn main() {
// TODO: Change the line below to fix the compiler error.
let x: i32;
println!("Number {x}");
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/01_variables/variables4.rs | exercises/01_variables/variables4.rs | // TODO: Fix the compiler error.
fn main() {
let x = 3;
println!("Number {x}");
x = 5; // Don't change this line
println!("Number {x}");
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/04_primitive_types/primitive_types3.rs | exercises/04_primitive_types/primitive_types3.rs | fn main() {
// TODO: Create an array called `a` with at least 100 elements in it.
// let a = ???
if a.len() >= 100 {
println!("Wow, that's a big array!");
} else {
println!("Meh, I eat arrays like that for breakfast.");
panic!("Array not big enough, more elements needed");
}... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/04_primitive_types/primitive_types1.rs | exercises/04_primitive_types/primitive_types1.rs | // Booleans (`bool`)
fn main() {
let is_morning = true;
if is_morning {
println!("Good morning!");
}
// TODO: Define a boolean variable with the name `is_evening` before the `if` statement below.
// The value of the variable should be the negation (opposite) of `is_morning`.
// let …
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/04_primitive_types/primitive_types6.rs | exercises/04_primitive_types/primitive_types6.rs | fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
#[test]
fn indexing_tuple() {
let numbers = (1, 2, 3);
// TODO: Use a tuple index to access the second element of `numbers`
// and assign it to a variable called `second`.
// let second = ???;
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/04_primitive_types/primitive_types2.rs | exercises/04_primitive_types/primitive_types2.rs | // Characters (`char`)
fn main() {
// Note the _single_ quotes, these are different from the double quotes
// you've been seeing around.
let my_first_initial = 'C';
if my_first_initial.is_alphabetic() {
println!("Alphabetical!");
} else if my_first_initial.is_numeric() {
println!("N... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/04_primitive_types/primitive_types4.rs | exercises/04_primitive_types/primitive_types4.rs | fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
#[test]
fn slice_out_of_array() {
let a = [1, 2, 3, 4, 5];
// TODO: Get a slice called `nice_slice` out of the array `a` so that the test passes.
// let nice_slice = ???
assert_eq!([2, 3, 4], nic... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/04_primitive_types/primitive_types5.rs | exercises/04_primitive_types/primitive_types5.rs | fn main() {
let cat = ("Furry McFurson", 3.5);
// TODO: Destructure the `cat` tuple in one statement so that the println works.
// let /* your pattern here */ = cat;
println!("{name} is {age} years old");
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/02_functions/functions5.rs | exercises/02_functions/functions5.rs | // TODO: Fix the function body without changing the signature.
fn square(num: i32) -> i32 {
num * num;
}
fn main() {
let answer = square(3);
println!("The square of 3 is {answer}");
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/02_functions/functions2.rs | exercises/02_functions/functions2.rs | // TODO: Add the missing type of the argument `num` after the colon `:`.
fn call_me(num:) {
for i in 0..num {
println!("Ring! Call number {}", i + 1);
}
}
fn main() {
call_me(3);
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/02_functions/functions4.rs | exercises/02_functions/functions4.rs | // This store is having a sale where if the price is an even number, you get 10
// Rustbucks off, but if it's an odd number, it's 3 Rustbucks off.
// Don't worry about the function bodies themselves, we are only interested in
// the signatures for now.
fn is_even(num: i64) -> bool {
num % 2 == 0
}
// TODO: Fix th... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/02_functions/functions1.rs | exercises/02_functions/functions1.rs | // TODO: Add some function with the name `call_me` without arguments or a return value.
fn main() {
call_me(); // Don't change this line
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/02_functions/functions3.rs | exercises/02_functions/functions3.rs | fn call_me(num: u8) {
for i in 0..num {
println!("Ring! Call number {}", i + 1);
}
}
fn main() {
// TODO: Fix the function call.
call_me();
}
| rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/12_options/options3.rs | exercises/12_options/options3.rs | #[derive(Debug)]
struct Point {
x: i32,
y: i32,
}
fn main() {
let optional_point = Some(Point { x: 100, y: 200 });
// TODO: Fix the compiler error by adding something to this match statement.
match optional_point {
Some(p) => println!("Coordinates are {},{}", p.x, p.y),
_ => panic!... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/12_options/options1.rs | exercises/12_options/options1.rs | // This function returns how much ice cream there is left in the fridge.
// If it's before 22:00 (24-hour system), then 5 scoops are left. At 22:00,
// someone eats it all, so no ice cream is left (value 0). Return `None` if
// `hour_of_day` is higher than 23.
fn maybe_ice_cream(hour_of_day: u16) -> Option<u16> {
/... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/12_options/options2.rs | exercises/12_options/options2.rs | fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
#[test]
fn simple_option() {
let target = "rustlings";
let optional_target = Some(target);
// TODO: Make this an if-let statement whose value is `Some`.
word = optional_target {
assert... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/06_move_semantics/move_semantics4.rs | exercises/06_move_semantics/move_semantics4.rs | fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
// TODO: Fix the compiler errors only by reordering the lines in the test.
// Don't add, change or remove any line.
#[test]
fn move_semantics4() {
let mut x = Vec::new();
let y = &mut x;
let z = &m... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/06_move_semantics/move_semantics3.rs | exercises/06_move_semantics/move_semantics3.rs | // TODO: Fix the compiler error in the function without adding any new line.
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
vec.push(88);
vec
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn move_semantics3() {
let vec0 = vec![22, 44,... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/06_move_semantics/move_semantics5.rs | exercises/06_move_semantics/move_semantics5.rs | #![allow(clippy::ptr_arg)]
// TODO: Fix the compiler errors without changing anything except adding or
// removing references (the character `&`).
// Shouldn't take ownership
fn get_char(data: String) -> char {
data.chars().last().unwrap()
}
// Should take ownership
fn string_uppercase(mut data: &String) {
d... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/06_move_semantics/move_semantics2.rs | exercises/06_move_semantics/move_semantics2.rs | fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
let mut vec = vec;
vec.push(88);
vec
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
// TODO: Make both vectors `vec0` and `vec1` accessible at the same time to
// fix the compiler error in the test.
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/exercises/06_move_semantics/move_semantics1.rs | exercises/06_move_semantics/move_semantics1.rs | // TODO: Fix the compiler error in this function.
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
let vec = vec;
vec.push(88);
vec
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn move_semantics1() {
let vec0 = vec![22, 44, 66];
... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
rust-lang/rustlings | https://github.com/rust-lang/rustlings/blob/7850a73d95c02840f4ab3bf8d9571b08410e5467/rustlings-macros/src/lib.rs | rustlings-macros/src/lib.rs | use proc_macro::TokenStream;
use quote::quote;
use serde::Deserialize;
#[derive(Deserialize)]
struct ExerciseInfo {
name: String,
dir: String,
}
#[derive(Deserialize)]
struct InfoFile {
exercises: Vec<ExerciseInfo>,
}
#[proc_macro]
pub fn include_files(_: TokenStream) -> TokenStream {
let info_file =... | rust | MIT | 7850a73d95c02840f4ab3bf8d9571b08410e5467 | 2026-01-04T15:31:58.719144Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/paging.rs | src/paging.rs | #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum PagingMode {
Always,
QuitIfOneScreen,
#[default]
Never,
}
| rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/config.rs | src/config.rs | use crate::line_range::{HighlightedLineRanges, LineRanges};
use crate::nonprintable_notation::{BinaryBehavior, NonprintableNotation};
#[cfg(feature = "paging")]
use crate::paging::PagingMode;
use crate::style::StyleComponents;
use crate::syntax_mapping::SyntaxMapping;
use crate::wrapping::WrappingMode;
use crate::Strip... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/nonprintable_notation.rs | src/nonprintable_notation.rs | /// How to print non-printable characters with
/// [crate::config::Config::show_nonprintable]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum NonprintableNotation {
/// Use caret notation (^G, ^J, ^@, ..)
Caret,
/// Use unicode notation (␇, ␊, ␀, ..)
#[default]
Unic... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/preprocessor.rs | src/preprocessor.rs | use std::fmt::Write;
use crate::{
nonprintable_notation::NonprintableNotation,
vscreen::{EscapeSequenceOffsets, EscapeSequenceOffsetsIterator},
};
/// Expand tabs like an ANSI-enabled expand(1).
pub fn expand_tabs(line: &str, width: usize, cursor: &mut usize) -> String {
let mut buffer = String::with_capa... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/decorations.rs | src/decorations.rs | #[cfg(feature = "git")]
use crate::diff::LineChange;
use crate::printer::{Colors, InteractivePrinter};
use nu_ansi_term::Style;
#[derive(Debug, Clone)]
pub(crate) struct DecorationText {
pub width: usize,
pub text: String,
}
pub(crate) trait Decoration {
fn generate(
&self,
line_number: us... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/lib.rs | src/lib.rs | //! `bat` is a library to print syntax highlighted content.
//!
//! The main struct of this crate is `PrettyPrinter` which can be used to
//! configure and run the syntax highlighting.
//!
//! If you need more control, you can also use the structs in the submodules
//! (start with `controller::Controller`), but note th... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/theme.rs | src/theme.rs | //! Utilities for choosing an appropriate theme for syntax highlighting.
use std::convert::Infallible;
use std::fmt;
use std::io::IsTerminal as _;
use std::str::FromStr;
/// Environment variable names.
pub mod env {
/// See [`crate::theme::ThemeOptions::theme`].
pub const BAT_THEME: &str = "BAT_THEME";
//... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/line_range.rs | src/line_range.rs | use crate::error::*;
use itertools::{Itertools, MinMaxResult};
#[derive(Debug, Copy, Clone)]
pub struct LineRange {
lower: RangeBound,
upper: RangeBound,
}
/// Defines a boundary for a range
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub(crate) enum RangeBound {
// An absolute line number marking the bo... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/diff.rs | src/diff.rs | #![cfg(feature = "git")]
use std::collections::HashMap;
use std::fs;
use std::path::Path;
use git2::{DiffOptions, IntoCString, Repository};
#[derive(Copy, Clone, Debug)]
pub enum LineChange {
Added,
RemovedAbove,
RemovedBelow,
Modified,
}
pub type LineChanges = HashMap<u32, LineChange>;
pub fn get_... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/wrapping.rs | src/wrapping.rs | #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WrappingMode {
Character,
// The bool specifies whether wrapping has been explicitly disabled by the user via --wrap=never
NoWrapping(bool),
}
impl Default for WrappingMode {
fn default() -> Self {
WrappingMode::NoWrapping(false)
}
}
| rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/controller.rs | src/controller.rs | use crate::assets::HighlightingAssets;
use crate::config::{Config, VisibleLines};
#[cfg(feature = "git")]
use crate::diff::{get_git_diff, LineChanges};
use crate::error::*;
use crate::input::{Input, InputReader, OpenedInput};
#[cfg(feature = "lessopen")]
use crate::lessopen::LessOpenPreprocessor;
#[cfg(feature = "git")... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/syntax_mapping.rs | src/syntax_mapping.rs | use std::{
path::Path,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
thread,
};
use globset::{Candidate, GlobBuilder, GlobMatcher};
use once_cell::sync::Lazy;
use crate::error::Result;
use builtin::BUILTIN_MAPPINGS;
use ignored_suffixes::IgnoredSuffixes;
mod builtin;
pub mod ignored... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/error.rs | src/error.rs | use std::io::Write;
use thiserror::Error;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
Io(#[from] ::std::io::Error),
#[error(transparent)]
Fmt(#[from] ::std::fmt::Error),
#[error(transparent)]
SyntectError(#[from] ::syntect::Error),
#[error(transparent)]
... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/printer.rs | src/printer.rs | use std::vec::Vec;
use nu_ansi_term::Color::{Fixed, Green, Red, Yellow};
use nu_ansi_term::Style;
use bytesize::ByteSize;
use syntect::easy::HighlightLines;
use syntect::highlighting::Color;
use syntect::highlighting::FontStyle;
use syntect::highlighting::Theme;
use syntect::parsing::SyntaxSet;
use content_inspecto... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/pretty_printer.rs | src/pretty_printer.rs | use std::io::Read;
use std::path::Path;
use console::Term;
use crate::{
assets::HighlightingAssets,
config::{Config, VisibleLines},
controller::Controller,
error::Result,
input,
line_range::{HighlightedLineRanges, LineRange, LineRanges},
output::OutputHandle,
style::StyleComponent,
... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/terminal.rs | src/terminal.rs | use nu_ansi_term::Color::{self, Fixed, Rgb};
use nu_ansi_term::{self, Style};
use syntect::highlighting::{self, FontStyle};
pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> Option<nu_ansi_term::Color> {
if color.a == 0 {
// Themes can specify one of the user-configurable terminal colo... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/macros.rs | src/macros.rs | #[macro_export]
macro_rules! bat_warning {
($($arg:tt)*) => ({
use nu_ansi_term::Color::Yellow;
eprintln!("{}: {}", Yellow.paint("[bat warning]"), format!($($arg)*));
})
}
| rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/style.rs | src/style.rs | use std::collections::HashSet;
use std::str::FromStr;
use crate::error::*;
#[non_exhaustive]
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
pub enum StyleComponent {
Auto,
#[cfg(feature = "git")]
Changes,
Grid,
Rule,
Header,
HeaderFilename,
HeaderFilesize,
LineNumbers,
Snip... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/vscreen.rs | src/vscreen.rs | use std::{
fmt::{Display, Formatter},
iter::Peekable,
str::CharIndices,
};
// Wrapper to avoid unnecessary branching when input doesn't have ANSI escape sequences.
pub struct AnsiStyle {
attributes: Option<Attributes>,
}
impl AnsiStyle {
pub fn new() -> Self {
AnsiStyle { attributes: None ... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/less.rs | src/less.rs | #![cfg(feature = "paging")]
use std::ffi::OsStr;
use std::process::Command;
#[derive(Debug, PartialEq, Eq)]
pub enum LessVersion {
Less(usize),
BusyBox,
}
pub fn retrieve_less_version(less_path: &dyn AsRef<OsStr>) -> Option<LessVersion> {
let resolved_path = grep_cli::resolve_binary(less_path.as_ref()).o... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/lessopen.rs | src/lessopen.rs | use std::convert::TryFrom;
use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader, Cursor, Read};
use std::path::PathBuf;
use std::process::{ExitStatus, Stdio};
use clircle::{Clircle, Identifier};
use execute::{shell, Execute};
use crate::error::Result;
use crate::{
bat_warning,
input::{Input, Inpu... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/assets.rs | src/assets.rs | use std::ffi::OsStr;
use std::fs;
use std::path::Path;
use once_cell::unsync::OnceCell;
use syntect::highlighting::Theme;
use syntect::parsing::{SyntaxReference, SyntaxSet};
use path_abs::PathAbs;
use crate::error::*;
use crate::input::{InputReader, OpenedInput};
use crate::syntax_mapping::ignored_suffixes::Ignored... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/output.rs | src/output.rs | use std::fmt;
use std::io;
#[cfg(feature = "paging")]
use std::process::Child;
#[cfg(feature = "paging")]
use std::thread::{spawn, JoinHandle};
use crate::error::*;
#[cfg(feature = "paging")]
use crate::less::{retrieve_less_version, LessVersion};
#[cfg(feature = "paging")]
use crate::paging::PagingMode;
#[cfg(feature ... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/pager.rs | src/pager.rs | use shell_words::ParseError;
use std::env;
/// If we use a pager, this enum tells us from where we were told to use it.
#[derive(Debug, PartialEq)]
pub(crate) enum PagerSource {
/// From --config
Config,
/// From the env var BAT_PAGER
EnvVarBatPager,
/// From the env var PAGER
EnvVarPager,
... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/input.rs | src/input.rs | use std::convert::TryFrom;
use std::fs;
use std::fs::File;
use std::io::{self, BufRead, BufReader, Read};
use std::path::{Path, PathBuf};
use clircle::{Clircle, Identifier};
use content_inspector::{self, ContentType};
use crate::error::*;
/// A description of an Input source.
/// This tells bat how to refer to the i... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/bin/bat/config.rs | src/bin/bat/config.rs | use std::env;
use std::ffi::OsString;
use std::fs;
use std::io::{self, Write};
use std::path::PathBuf;
use crate::directories::PROJECT_DIRS;
#[cfg(not(target_os = "windows"))]
const DEFAULT_SYSTEM_CONFIG_PREFIX: &str = "/etc";
#[cfg(target_os = "windows")]
const DEFAULT_SYSTEM_CONFIG_PREFIX: &str = "C:\\ProgramData"... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/bin/bat/app.rs | src/bin/bat/app.rs | use std::collections::HashSet;
use std::env;
use std::io::IsTerminal;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::thread::available_parallelism;
use crate::{
clap_app,
config::{get_args_from_config_file, get_args_from_env_opts_var, get_args_from_env_vars},
};
use bat::style::StyleComponentL... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/bin/bat/directories.rs | src/bin/bat/directories.rs | use std::env;
use std::path::{Path, PathBuf};
use etcetera::BaseStrategy;
use once_cell::sync::Lazy;
/// Wrapper for 'etcetera' that checks BAT_CACHE_PATH and BAT_CONFIG_DIR and falls back to the
/// Windows known folder locations on Windows & the XDG Base Directory Specification everywhere else.
pub struct BatProjec... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/bin/bat/completions.rs | src/bin/bat/completions.rs | use std::env;
pub const BASH_COMPLETION: &str = include_str!(env!("BAT_GENERATED_COMPLETION_BASH"));
pub const FISH_COMPLETION: &str = include_str!(env!("BAT_GENERATED_COMPLETION_FISH"));
pub const PS1_COMPLETION: &str = include_str!(env!("BAT_GENERATED_COMPLETION_PS1"));
pub const ZSH_COMPLETION: &str = include_str!(... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/bin/bat/clap_app.rs | src/bin/bat/clap_app.rs | use bat::style::StyleComponentList;
use clap::{
crate_name, crate_version, value_parser, Arg, ArgAction, ArgGroup, ColorChoice, Command,
};
use once_cell::sync::Lazy;
use std::env;
use std::path::{Path, PathBuf};
use std::str::FromStr;
static VERSION: Lazy<String> = Lazy::new(|| {
#[cfg(feature = "bugreport")]... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | true |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/bin/bat/main.rs | src/bin/bat/main.rs | #![deny(unsafe_code)]
mod app;
mod assets;
mod clap_app;
#[cfg(feature = "application")]
mod completions;
mod config;
mod directories;
mod input;
use std::collections::{HashMap, HashSet};
use std::fmt::Write as _;
use std::io;
use std::io::{BufReader, Write};
use std::path::Path;
use std::process;
use bat::output::{... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/bin/bat/assets.rs | src/bin/bat/assets.rs | use std::fs;
use std::io;
use std::path::Path;
use std::path::PathBuf;
use clap::crate_version;
use bat::assets::HighlightingAssets;
use bat::assets_metadata::AssetsMetadata;
use bat::error::*;
pub fn clear_assets(cache_dir: &Path) {
clear_asset(cache_dir.join("themes.bin"), "theme set cache");
clear_asset(c... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/bin/bat/input.rs | src/bin/bat/input.rs | use bat::input::Input;
use std::path::Path;
pub fn new_file_input<'a>(file: &'a Path, name: Option<&'a Path>) -> Input<'a> {
named(Input::ordinary_file(file), name.or(Some(file)))
}
pub fn new_stdin_input(name: Option<&Path>) -> Input<'_> {
named(Input::stdin(), name)
}
fn named<'a>(input: Input<'a>, name: O... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
sharkdp/bat | https://github.com/sharkdp/bat/blob/4e84e838a32e3b326a3d1f9e2cd4c879597ad74d/src/assets/build_assets.rs | src/assets/build_assets.rs | use std::convert::TryInto;
use std::path::Path;
use syntect::highlighting::ThemeSet;
use syntect::parsing::{SyntaxSet, SyntaxSetBuilder};
use crate::assets::*;
use acknowledgements::build_acknowledgements;
mod acknowledgements;
pub fn build(
source_dir: &Path,
include_integrated_assets: bool,
include_ac... | rust | Apache-2.0 | 4e84e838a32e3b326a3d1f9e2cd4c879597ad74d | 2026-01-04T15:31:58.743241Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.