blob_id stringlengths 40 40 | language stringclasses 1
value | repo_name stringlengths 5 140 | path stringlengths 5 183 | src_encoding stringclasses 6
values | length_bytes int64 12 5.32M | score float64 2.52 4.94 | int_score int64 3 5 | detected_licenses listlengths 0 47 | license_type stringclasses 2
values | text stringlengths 12 5.32M | download_success bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|
090566a92eaefe7705438a1a6eb6c174055c9834 | Rust | nventuro/adventofcode-rust | /day-04/src/main.rs | UTF-8 | 2,323 | 3.765625 | 4 | [
"MIT"
] | permissive | fn main() {
process("172930", "683082");
}
fn process(start: &str, end: &str) {
let total = password_range(start, end)
.map(|v| v.to_string())
.filter(|p| is_valid(p))
.count();
println!("Valid passwords: {}", total);
}
fn password_range(start: &str, end: &str) -> std::ops::Range<... | true |
9604e1ebb55d1b9a3f201e6a581b986af7e33913 | Rust | VETER1309/identity.rs | /identity_core/src/resolver/error_kind.rs | UTF-8 | 585 | 2.609375 | 3 | [
"Apache-2.0"
] | permissive | use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
pub enum ErrorKind {
/// The DID supplied to the DID resolution function does not conform to
/// valid syntax.
#[serde(rename = "invalid-did")]
InvalidDID,
/// The DID re... | true |
6d4c35e563637987fa1ac75affb776cd71c62f75 | Rust | hgbdev/moon | /components/message/src/lib.rs | UTF-8 | 4,660 | 2.875 | 3 | [
"MIT"
] | permissive | mod general;
mod notification;
mod request;
use ipc::{IpcTransportError, Message};
use serde::{Deserialize, Serialize};
use std::io::prelude::*;
pub use general::*;
pub use notification::*;
pub use request::*;
#[derive(Debug, Serialize, Deserialize)]
pub enum BrowserMessage {
Request(RawRequest),
Response(Ra... | true |
a7450bc49331fd4e729317e409016d5d543ffa41 | Rust | samwho/advent-of-code-2020 | /src/4.rs | UTF-8 | 5,829 | 3.265625 | 3 | [] | no_license | use lazy_static::lazy_static;
use regex::Regex;
use std::{error::Error, fs::File, io::BufRead, io::BufReader, str::FromStr};
lazy_static! {
static ref HEIGHT_REGEX: Regex = Regex::new(r"^(\d+)(cm|in)$").unwrap();
static ref COLOR_REGEX: Regex = Regex::new(r"^#([0-9a-f]{6})$").unwrap();
static ref NINE_DIGI... | true |
6e9682ee88450931ea241bec0b05877dc828a868 | Rust | angelini/df | /src/pool.rs | UTF-8 | 2,255 | 3.125 | 3 | [] | no_license | use std::collections::HashMap;
use std::fmt;
use std::sync::{Arc, Mutex};
use rand::{self, Rng};
use block::Block;
use value::Value;
#[derive(Debug)]
pub enum Error {
MissingIndex(u64),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
E... | true |
20868f96f4ce05ae75eca2d91bd8f3a86a1e1131 | Rust | museun/brain | /crates/markov/src/markov.rs | UTF-8 | 6,203 | 2.859375 | 3 | [
"Unlicense"
] | permissive | use crate::*;
#[derive(Clone, Serialize, Deserialize)]
pub struct Markov {
pub chain: HashMap<Vec<Vec<u8>>, LinkSet>,
pub starts: HashSet<Vec<u8>>,
pub depth: usize,
pub name: String,
}
impl Markov {
pub fn new(depth: usize, name: impl ToString + std::fmt::Debug) -> Self {
Markov {
... | true |
55d6bfcfd478f57a2fae648f14d1dae14bb0cd3f | Rust | remexre/csci5607-game | /src/util.rs | UTF-8 | 3,661 | 2.90625 | 3 | [] | no_license | //! Miscellaneous utilities.
use failure::{Error, Fallible, ResultExt};
use glium::texture::RawImage2d;
use image;
use serde::Deserialize;
use serde_json::from_reader;
use std::{
collections::HashMap,
fs::{canonicalize, File},
io::Read,
path::{Path, PathBuf},
str::FromStr,
sync::{Arc, Mutex, We... | true |
671f1328a6abead1e0758678bb0defce5e6e8b0e | Rust | theironsavior/DATIS | /crates/datis-core/src/ipc.rs | UTF-8 | 3,876 | 2.734375 | 3 | [
"MIT"
] | permissive | use std::ops::Deref;
use std::sync::Arc;
use crate::station::{LatLngPosition, Position};
use crate::weather::{Clouds, WeatherInfo};
use dcs_module_ipc::Error;
use serde::Deserialize;
use serde_json::json;
pub struct MissionRpcInner {
ipc: dcs_module_ipc::IPC<()>,
clouds: Option<Clouds>,
fog_thickness: u32... | true |
2e49ba858fe7181e4004a19413eee25171a8831c | Rust | NaomiLea/ji-cloud | /backend/api/src/jwkkeys.rs | UTF-8 | 5,605 | 2.578125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use crate::extractor::FirebaseId;
use anyhow::{anyhow, bail, Context};
use jsonwebtoken as jwt;
use jwt::{Algorithm, DecodingKey, TokenData, Validation};
use reqwest::{header, Response};
use serde::Deserialize;
use std::{
sync::Arc,
time::{Duration, Instant},
};
use tokio::{sync::RwLock, task::JoinHandle};
#[d... | true |
8206d8e4ae04d3dd6200d45ee00cfc9ce80d8f62 | Rust | gabcoh/tauri | /core/tauri-utils/src/html.rs | UTF-8 | 1,868 | 2.53125 | 3 | [
"Apache-2.0",
"CC-BY-NC-ND-4.0",
"MIT",
"CC0-1.0"
] | permissive | // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use html5ever::{
interface::QualName,
namespace_url, ns,
tendril::{fmt::UTF8, NonAtomic, Tendril},
LocalName,
};
use kuchiki::{traits::*, Attribute, ExpandedName, NodeRef... | true |
bcee9a64bc82c937a1255d7d9f71c2265c7cea27 | Rust | bjgill/toml_edit | /src/array_of_tables.rs | UTF-8 | 1,165 | 3.765625 | 4 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use table::Table;
/// Type representing a TOML array of tables
#[derive(Clone, Debug, Default)]
pub struct ArrayOfTables {
pub(crate) values: Vec<Table>,
}
impl ArrayOfTables {
pub fn new() -> Self {
Default::default()
}
/// Returns an iterator over tables
pub fn iter<'a>(&'a self) -> Box... | true |
7762d99d71bf0d1ab0d35aa8f1bfe02104b28322 | Rust | jtavera235/MultiClassMapper | /src/deparser/deparser.rs | UTF-8 | 3,972 | 2.96875 | 3 | [] | no_license | use crate::common::{create_file, handle_result_error, write_file, MError};
use crate::models::{Access, Language};
use crate::objects::Class;
use colored::Colorize;
pub struct DeParser {
pub objects: Vec<Class>,
}
impl DeParser {
pub fn new(objects: Vec<Class>) -> DeParser {
DeParser { objects }
}
... | true |
01c5ad5f46cd7915d6dc6b89f2e12d0c73ab0029 | Rust | Tedford/Exercism | /rust/clock/src/lib.rs | UTF-8 | 1,005 | 3.484375 | 3 | [] | no_license | use std::fmt;
const MINUTES_PER_HOUR: i32 = 60;
const HOURS_PER_DAY: i32 = 24;
const MINUTES_PER_DAY: i32 = MINUTES_PER_HOUR * HOURS_PER_DAY;
#[derive(PartialEq, Debug)]
pub struct Clock {
offset: i32,
}
impl Clock {
fn calculate_offset(base: i32, change: i32) -> i32 {
(base + change).rem_euclid(MINU... | true |
987a4675403d2d3614e7c0068d088f0de66bd252 | Rust | shifteight/rust | /byexample/guards.rs | UTF-8 | 486 | 3.53125 | 4 | [] | no_license | fn main() {
let pairs = vec!{(2, -2), (1, 1), (3, 1), (4,1)};
for pair in pairs {
println!("Tell me about {:?}", pair);
tell_about_pair(pair);
}
}
fn tell_about_pair(pair: (i32, i32)) {
match pair {
(x, y) if x == y => println!("These are twins"),
(x, y) if x + y == 0 => prin... | true |
fd9a95cf0c306439e61cc1ac5b378fd033520604 | Rust | willi-kappler/comment_units | /src/fortran/tests/parse_implicit.rs | UTF-8 | 1,577 | 2.5625 | 3 | [
"MIT"
] | permissive | use nom::{IResult, Needed, Err, ErrorKind};
use super::super::{FortranTokenType, parse_implicit};
#[test]
fn parse_implicit1() {
let input = "";
let expected_output = IResult::Incomplete(Needed::Size(8));
let result = parse_implicit(input);
assert_eq!(result, expected_output);
}
#[test]
fn parse_im... | true |
99ce2ee10411aba6a2b04920011ca05b8909fabc | Rust | xta0/CodeBase | /rust/src/ds.rs | UTF-8 | 2,625 | 3.65625 | 4 | [] | no_license | #[allow(dead_code)]
#[allow(unused_variables)]
use std::mem;
struct Point {
x: f64,
y: f64,
}
enum Color {
Red,
Green,
Blue,
RgbColor(u8, u8, u8),
}
// 32 bits
union IntOrFloat {
i: i32,
f: f32,
}
pub fn enums() {
let c: Color = Color::Red;
match c {
Color::Red => prin... | true |
162704094120a54c4b84a12a86cabc22dbd4095a | Rust | Dooskington/LD46-Lighthouse-Keeper | /src/game/log.rs | UTF-8 | 1,706 | 2.53125 | 3 | [
"Zlib"
] | permissive | use crate::game::{physics::*, Point2d, *};
use gfx::input::*;
use ncollide2d::pipeline::CollisionGroups;
use rand::Rng;
use specs::prelude::*;
#[derive(Clone)]
pub struct LogEvent {
pub message: String,
pub color: Color,
}
#[derive(Default)]
pub struct LogState {
pub logs: Vec<LogEvent>,
}
#[derive(Defau... | true |
27bb944d18fd2ea461ae4b8c8fa38c6d75e6b39a | Rust | RJPlog/aoc-2020 | /day05/wasm-rust/subesokun/src/solution.rs | UTF-8 | 1,785 | 3.28125 | 3 | [
"MIT"
] | permissive | //tag::star1[]
fn calculate_seat_ids(seat_code_list: std::vec::Vec<String>) -> std::vec::Vec<u32> {
let mut seat_ids: std::vec::Vec<u32> = Vec::new();
for seat_code in seat_code_list.iter() {
let mut min_row: u32 = 0;
let mut max_row: u32 = 127;
let mut min_column: u32 = 0;
let m... | true |
b8ad0c4914719027a628bbb2e54a93e39ae88087 | Rust | CptBread/aoc-2020 | /src/day11.rs | UTF-8 | 2,504 | 3.125 | 3 | [] | no_license | use vek::vec::repr_c::{Vec2};
use crate::utils::Array2D;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Tile {
Floor,
Seat,
Taken,
}
use Tile::*;
#[allow(dead_code)]
fn tile_to_char(t: &Tile) -> char{
match t {
Floor => '.',
Seat => 'L',
Taken => '#',
}
}
pub fn solve() {
let mut seats = Array2D::load... | true |
f01f8b0eadd7e02feaea61cba88785960aae705c | Rust | rajin-s/specs | /src/compiler/_old/internal.rs | UTF-8 | 5,487 | 2.875 | 3 | [] | no_license | use std::collections::VecDeque;
// All passes get access to basic stuff
pub use crate::language::*;
pub use crate::utilities::Indirect;
pub use node::all::*;
use crate::errors::compile_error::*;
pub trait PassState
{
fn empty() -> Self;
}
pub trait CompilerPass<TState: PassState>
{
// Get the name of the pa... | true |
7cc98e1302f70d1ac3b9e74da52b22deec660ab3 | Rust | alexthemitchell/blott | /src/main.rs | UTF-8 | 2,713 | 3 | 3 | [] | no_license | #[macro_use]
extern crate clap;
extern crate time;
use std::any::Any;
use std::path::PathBuf;
mod render;
mod tweet;
mod publish;
static DATE_FORMAT: &'static str = "%A, %B %e, %Y@%H:%M";
fn main() {
let matches = clap_app!
(blott =>
(version: "1.0")
(author: "Alex Mitchell <alex@alext... | true |
f00d40cb9412e27e5363485633c7260d81644511 | Rust | anjone/sd | /rust/rust-app-sd/rocket-sd/src/entity/post.rs | UTF-8 | 854 | 2.5625 | 3 | [] | no_license | use rocket::serde::{Deserialize, Serialize};
//use crate::entity::user;
use sea_orm::entity::prelude::*;
use std::convert::TryInto;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize, FromForm)]
#[serde(crate = "rocket::serde")]
#[sea_orm(table_name = "post")]
pub struct Model {
#[sea_... | true |
94ec7855c16515648f2dfbb09bde32d56ee926be | Rust | adjivas/telamon | /src/ir/types.rs | UTF-8 | 1,376 | 3.53125 | 4 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | /// Describes the types instruction and operands can take.
use ir;
use std::fmt;
use utils::*;
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
/// Values and intructions types.
pub enum Type {
/// Type for integer values, with a fixed number of bits.
I(u16),
/// Type for floating point values, with a fi... | true |
64c3baf887ae72ffdd15c9fd643c8c00848c801e | Rust | Jikstra/nanokontrol-sane-rs | /src/log.rs | UTF-8 | 1,704 | 3.4375 | 3 | [] | no_license | use std::time::Instant;
use std::fmt::{Display, Formatter, Result};
pub enum LogLevel {
DEBUG,
INFO,
WARN,
VERBOSE,
ERROR
}
impl LogLevel {
fn to_string(&self) -> String {
match &self {
LogLevel::DEBUG => "d".to_string(),
LogLevel::INFO => "i".to_string(),
LogLevel::WARN => "w".to_string(),
LogLe... | true |
bc8c92b5d168df5ce6bf62f7279dd815d79289ee | Rust | thomascharbonnel/aaaaaaaaaaaa | /src/bin/level3.rs | UTF-8 | 1,092 | 3.0625 | 3 | [] | no_license | use std::io::{BufRead, BufReader, Error, ErrorKind};
use reqwest::StatusCode;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let first_arg = std::env::args().nth(1).ok_or(Error::new(ErrorKind::NotFound, "File name is missing"))?;
println!("Args: {}", first_arg);
let urls = read_file(&first_arg)?;
... | true |
9ca3dc7bd57ccfa46727c49c867a26644fc6e274 | Rust | zhangkefei/cli_color_log | /src/main.rs | UTF-8 | 454 | 2.625 | 3 | [] | no_license | use cli_color_log::Logger;
use cli_color_log::LogType;
fn main() {
let logger = Logger::new(12);
logger.info("This is a info message.");
logger.warn("This is a warning message.");
logger.error("This is a error message.");
logger.style_log(LogType::Info, "Download", "This is a custom style message.")... | true |
31efbf559a48fb2040fd151a704cbe28af859f3a | Rust | CornedBee/AdventOfCode2017 | /day12/src/main.rs | UTF-8 | 1,395 | 2.859375 | 3 | [
"MIT"
] | permissive | extern crate disjoint_sets;
#[macro_use] extern crate scan_rules;
use std::io;
struct Program {
id: usize,
connections: Vec<usize>,
}
fn read_program() -> Result<Option<Program>, scan_rules::ScanError> {
let mut line = String::new();
match io::stdin().read_line(&mut line) {
Err(e) => Err(scan... | true |
5fd18c2b593d2fa4245faa92ef916f270a933ebd | Rust | sugyan/leetcode | /others/february-leetcoding-challenge-2021/week-2/3637/lib.rs | UTF-8 | 496 | 3.25 | 3 | [] | no_license | pub struct Solution;
impl Solution {
pub fn number_of_steps(num: i32) -> i32 {
(31 + num.count_ones()).saturating_sub(num.leading_zeros()) as i32
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn example_1() {
assert_eq!(6, Solution::number_of_steps(14));
}
#[test]
... | true |
1531d0649d0ad27c4c83a99d6880f5149aacfe69 | Rust | tickbh/rbtree-rs | /examples/bench.rs | UTF-8 | 2,359 | 3.1875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] | permissive | extern crate rbtree;
use rbtree::RBTree;
use std::time::{Duration, Instant};
use std::cmp;
fn duration_to_num(duration: Duration) -> u64 {
duration.as_secs() * 1_000_000_000 + duration.subsec_nanos() as u64
}
fn test_insert(repeat: u64, insert: u64) {
let mut sum = 0;
let mut max = 0;
let mut min = ::... | true |
a5936a7ddd63505b4bc5324431e20b9e482492d7 | Rust | emilio/rustc-perf | /collector/benchmarks/sentry-cli/src/commands/difutil_uuid.rs | UTF-8 | 1,675 | 2.65625 | 3 | [
"MIT",
"BSD-2-Clause"
] | permissive | use std::io;
use std::path::Path;
use clap::{App, Arg, ArgMatches};
use serde_json;
use prelude::*;
use config::Config;
use utils::dif;
pub fn make_app<'a, 'b: 'a>(app: App<'a, 'b>) -> App<'a, 'b> {
app
.about("Given a debug info file spits out the UUID(s) of it")
.arg(Arg::with_name("type")
... | true |
5dc0a8e8cd88b309c62075b92ee33107b2c1c012 | Rust | SteadBytes/study | /the-rust-programming-language/projects/lifetimes/src/main.rs | UTF-8 | 1,873 | 4.21875 | 4 | [] | no_license | fn main() {
// Dangling pointers
// Won't compile - y does not 'live long enough'
// {
// let x;
// {
// let y = 10;
// y = &x; // y borrows x
// }
// // y dropped here
// println!("x: {}", x); // x refers to borrowed y which does not exist h... | true |
0afea27616501f58bdb92fa0cb5cc5514b88bfce | Rust | graydon/imp | /imp_language/src/solver.rs | UTF-8 | 13,828 | 2.9375 | 3 | [] | no_license | use crate::shared::*;
// #[derive(Debug, Clone)]
// pub struct ContainsContext<'a> {
// pub scalar_cache: &'a Cache<bool>,
// pub type_cache: &'a Cache<ValueType>,
// pub gensym: &'a Gensym,
// }
// impl Expression {
// pub fn solve(&self, context: &ContainsContext) -> Result<Self, String> {
// ... | true |
08ece80d50e5edbc6a427954c189128f5f7feb33 | Rust | apheon-terra/image-roll | /src/file_list.rs | UTF-8 | 5,766 | 2.53125 | 3 | [
"MIT"
] | permissive | use std::path::PathBuf;
use anyhow::{anyhow, Context, Result};
use gtk::{
gio::{self, Cancellable, FileMonitorFlags, FileQueryInfoFlags, FileType},
prelude::FileExt,
};
pub struct FileList {
file_list: Vec<gio::FileInfo>,
current_file: Option<(usize, gio::File)>,
current_folder: Option<gio::File>,... | true |
569b860baaad9898c4006596c9f1fc370eb2db23 | Rust | mozilla-services/megapush | /src/client_state/mod.rs | UTF-8 | 4,504 | 3.359375 | 3 | [] | no_license | #[macro_use]
extern crate state_machine_future;
#[macro_use]
extern crate futures;
use futures::{Async, Future, Poll};
use state_machine_future::RentToOwn;
/// The result of a game.
pub struct GameResult {
winner: Player,
loser: Player,
}
/// Some kind of simple turn based game.
///
/// ```text
/// ... | true |
3aa8e2fdc7cc6336b2455361d3e7e5fa29ece839 | Rust | tel/aoc2020 | /src/daynine.rs | UTF-8 | 3,560 | 3.140625 | 3 | [
"Apache-2.0"
] | permissive | use std::fs;
use std::cmp::Ordering;
#[derive(Clone)]
struct XmasStream {
value: i64,
origi: usize,
validated: i32,
}
impl XmasStream {
pub fn new(value: i64, origi: usize) -> Self {
Self {
value,
origi,
validated: 0,
}
}
}
pub fn execute_daynin... | true |
12361f90f338175f312d41297b42c25b49630386 | Rust | KilianVounckx/truster | /src/tuple.rs | UTF-8 | 10,516 | 4.21875 | 4 | [] | no_license | //! A 3D tuple which can represent points and vectors.
//! The coordinates are floating point numbers. Support for generics may be added in the future.
//!
//! # Examples
//!
//! You can create points and vectors with [Tuple::point] and [Tuple::vector] respectively:
//! ```
//! # use truster::tuple::Tuple;
//! let p = ... | true |
d67ac7a384251968c1da63122ce62d1b9fd163fc | Rust | cmyr/RustPlayground | /playground-utils/src/compile.rs | UTF-8 | 7,441 | 3.109375 | 3 | [
"Apache-2.0"
] | permissive | use std::fs;
use std::io::{BufRead, BufReader};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use crate::error::Error;
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "snake_case")]
enum Type {
Run,
Check,
Test,
Clean,
}
impl Type {
fn as_str(&self) -> &str {
... | true |
a0ed13509a698aef426df42c2b5170381daa3286 | Rust | LukeStorry/advent-of-code-2020 | /rust/src/day9.rs | UTF-8 | 2,208 | 3.609375 | 4 | [] | no_license | use std::fs::read_to_string;
fn get_input() -> Vec<i32> {
read_to_string("../inputs/9.txt").unwrap()
.split_whitespace()
.flat_map(|i| i.parse())
.collect()
}
pub fn solve() {
let numbers = get_input();
print!("Day 9 part 1: {}\n", part_1(&numbers, 25));
print!("Day 9 part 2: {... | true |
9986c41015d8602451eeefb34d9e72ef3308820d | Rust | william20111/wash | /src/bin/wash.rs | UTF-8 | 974 | 2.6875 | 3 | [
"MIT"
] | permissive | extern crate wash;
use std::io;
use std::io::Write;
use std::path::Path;
use std::thread;
use std::error::Error;
use std::env;
use std::fs;
use wash::prompt::Prompt;
use wash::history::History;
use wash::parser;
fn main() {
// setup history
//let mut x: Vec<i8> = vec![1, 2, 3, 4, 5, 6];
//let x2 = x.spli... | true |
3a806ad7d05c939d77c5a030e7113f08d066a527 | Rust | dkaste/tcrab | /tcrab_console/src/color.rs | UTF-8 | 920 | 3.203125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | #[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
impl Color {
pub const WHITE: Color = Color { r: 255, g:... | true |
81f3524f2931c9645420d2f8a8c4f3af4a6be0ea | Rust | iambotHQ/zalando-api-client | /src/models/facet_value.rs | UTF-8 | 1,527 | 2.578125 | 3 | [] | no_license | /*
* Zalando Shop API
*
* The shop API empowers developers to build amazing new apps or websites using Zalando shop data and services.
*
* OpenAPI spec version: v1.0
*
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/
/// FacetValue : Zalando API FacetValue Schema
#[derive(Debug, Seriali... | true |
3efd720f63af1594934f82aafee3a86101264bf9 | Rust | rivy/rs.pretty_assertions | /tests/assert_eq.rs | UTF-8 | 13,920 | 3.03125 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #[allow(unused_imports)]
use pretty_assertions::{assert_eq, assert_ne};
use pretty_assertions::with_config_assert_eq;
use maybe_unwind::maybe_unwind;
fn test_setup() {
// set panic() hook for maybe_unwind
static SET_PANIC_HOOK: std::sync::Once = std::sync::Once::new();
SET_PANIC_HOOK.call_once(maybe_unwi... | true |
71410604d0eb64cc75cf3590095f25ab2e4936e3 | Rust | JonathanWoollett-Light/splitter | /src/main.rs | UTF-8 | 14,156 | 2.828125 | 3 | [] | no_license | extern crate image;
use std::path::Path;
use itertools::izip;
use std::env;
use image::{ImageBuffer, Rgb,Luma};
use image::imageops::FilterType;
use std::time::Instant;
use std::collections::VecDeque;
use std::fs::File;
use std::fs;
// Overall O'notation of 4n(ish) (n being image size=width*height)
// I think that's pr... | true |
8557c4f449f424048e2059316e73d207a61b72ff | Rust | adrianwithah/intercom-example | /intercom/src/alloc.rs | UTF-8 | 3,735 | 2.59375 | 3 | [
"MIT"
] | permissive |
use super::*;
use std::os::raw;
/// A memory allocator to be used for allocating/deallocating memory shared
/// with intercom libraries.
#[com_class( IAllocator )]
#[derive(Default)]
pub struct Allocator;
#[com_interface(
com_iid = "18EE22B3-B0C6-44A5-A94A-7A417676FB66",
raw_iid = "7A6F6564-04B5-4455... | true |
7a2d5baaf1a4b01b195cb023da80b3e8df7c10f2 | Rust | corytodd/AoC-2019 | /common/src/security.rs | UTF-8 | 4,384 | 3.5625 | 4 | [] | no_license | use std::collections::HashMap;
pub struct Login {
password_len: usize,
range_start: i32,
range_end: i32,
strict: bool,
}
impl Login {
pub fn new(required_len: usize, min_value: i32, max_value: i32, strict: bool) -> Login {
Login {
password_len: required_len,
range_s... | true |
1d512c256a964278ab406dc1c953a8e9bf1f8afe | Rust | xande0812/cp-rs | /AtCoder/000_ABS/abc081_a/src/main.rs | UTF-8 | 337 | 3.125 | 3 | [] | no_license | fn read_stdio<T: std::str::FromStr>() -> T {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
s.trim().parse().ok().unwrap()
}
fn main() {
let tmp: u32 = read_stdio::<String>()
.chars()
.map(|x| x.to_digit(10).unwrap())
.fold(0, |acc, x| acc + x);
println!... | true |
059da8ffa12f44a620f056bbb16dd2b8ae53bff6 | Rust | bridger-herman/wasm-logger | /src/lib.rs | UTF-8 | 2,489 | 3.234375 | 3 | [
"MIT"
] | permissive | //! A logger that prints all messages with a readable output format.
extern crate log;
extern crate wasm_bindgen;
use log::{Level, Log, Metadata, Record, SetLoggerError};
use wasm_bindgen::prelude::*;
#[macro_export]
macro_rules! error_panic {
($msg:expr) => {
error!($msg);
panic!();
};
... | true |
b906edcecb80e7766a8a4f9a0b4758828a9719e1 | Rust | Wilfred/difftastic | /src/version.rs | UTF-8 | 1,186 | 2.65625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] | permissive | use std::fmt;
use lazy_static::lazy_static;
pub struct CommitInfo {
pub short_commit_hash: &'static str,
pub commit_hash: &'static str,
pub commit_date: &'static str,
}
pub struct VersionInfo {
pub version: &'static str,
pub commit_info: Option<CommitInfo>,
}
impl fmt::Display for VersionInfo {
... | true |
e88b39357737f6188510c256a28b4e42101df107 | Rust | Sushisource/Rustlike | /src/dungeongen/direction.rs | UTF-8 | 2,227 | 3.6875 | 4 | [] | no_license | use std::slice::Iter;
#[derive(PartialEq, Debug, Clone, Copy, Eq, Hash)]
pub enum Direction {
North,
NorthEast,
East,
SouthEast,
South,
SouthWest,
West,
NorthWest,
}
impl Direction {
pub fn iterator() -> Iter<'static, Direction> {
static DIRECTIONS: [Direction; 8] = [
Direction::North,
... | true |
77ceb3c0b6c755d612b9ccdc761bcfe51891b771 | Rust | Kyle-Verhoog/rust-bytecode-vm | /src/main.rs | UTF-8 | 5,323 | 2.703125 | 3 | [] | no_license | #![allow(dead_code)] // FIXME: enable this again once things are stable
mod agent;
mod compiler;
mod debuginfo;
mod interpreter;
mod module;
mod opcode;
mod value;
use std::collections::HashMap;
use std::rc::Rc;
use std::io::{self, Write};
use agent::Agent;
use compiler::Compiler;
use interpreter::Interpreter;
use v... | true |
1015baf29082b4a3886642e191667318267cc411 | Rust | bytecodealliance/wasmtime | /cranelift/codegen/src/machinst/buffer.rs | UTF-8 | 97,865 | 3.484375 | 3 | [
"LLVM-exception",
"Apache-2.0"
] | permissive | //! In-memory representation of compiled machine code, with labels and fixups to
//! refer to those labels. Handles constant-pool island insertion and also
//! veneer insertion for out-of-range jumps.
//!
//! This code exists to solve three problems:
//!
//! - Branch targets for forward branches are not known until lat... | true |
e8b80a1002dbedbc282760b873336878652ef77c | Rust | aschampion/rust-n5 | /src/tests.rs | UTF-8 | 11,642 | 2.625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] | permissive | use super::*;
use std::io::{Cursor, Result};
use serde_json::json;
const DOC_SPEC_BLOCK_DATA: [i16; 6] = [1, 2, 3, 4, 5, 6];
pub(crate) trait N5Testable: N5Reader + N5Writer {
type Wrapper: AsRef<Self>;
fn temp_new_rw() -> Self::Wrapper;
fn open_reader(&self) -> Self;
}
/// Wrapper type for holding a ... | true |
db1782fe4fea118ed3ab55b80318cd5230de76b6 | Rust | q231950/paper | /src/resource/authentication_resource.rs | UTF-8 | 1,129 | 2.578125 | 3 | [] | no_license | use crate::resource::Resource;
use crate::model::SessionToken;
use crate::xml::AuthXmlParser;
use std::io::Read;
pub struct AuthenticationResource {
pub username: String,
pub password: String
}
impl Resource<SessionToken> for AuthenticationResource {
fn parse(&self, bytes: impl Read) -> Result<SessionTo... | true |
97780b9c9109bad559ba02630009e44b09bcf501 | Rust | ndouglas/downdelving | /src/demos/lighting_system.rs | UTF-8 | 7,177 | 2.53125 | 3 | [
"Unlicense"
] | permissive | use crate::demos::Demo;
use crate::gui;
use crate::map;
use crate::map_builders::level_builder;
use crate::perception::field_of_view::field_of_view as shadowcasting_fov;
use crate::RunState;
use derivative::Derivative;
use map::{get_tile_renderable, TileType};
use rltk::prelude::field_of_view as bracket_fov;
use rltk::... | true |
47e78d3b9dfa8edaaf06f2e5847b6dc4b2bf859c | Rust | Bugvi-Benjamin-M/Kattis | /rust/parking/src/main.rs | UTF-8 | 628 | 3.03125 | 3 | [
"MIT"
] | permissive | use std::io;
fn input () -> String
{
let mut ret = String::new();
io::stdin().read_line(&mut ret).expect("Failed to read from stdin");
ret
}
fn main() {
let t: u8 = input().trim().parse().unwrap();
for _ in 0..t {
let _ = input();
let mut store_locations: Vec... | true |
baab5697461661db52dd347c092eb60d01918266 | Rust | join3r/domaca1 | /src/main.rs | UTF-8 | 872 | 2.515625 | 3 | [] | no_license | mod lib;
use lib::{get_input_from_user, get_random_number};
// s použitím funkcií get_input_from_user a get_random_number vytvorte program, ktorý
// 1. vytvorí náhodné čislo s pomocou funkcie get_random_number
// 2. vypýta si číslo od užívateľa pomocou get_input_from_user
// 3. Ak užívateľ číslo uhádne, program mu zag... | true |
3c151f8dc7945be00a2b85801a63e72bc95cc8b2 | Rust | danbev/learning-rust | /src/leak.rs | UTF-8 | 374 | 3.40625 | 3 | [] | no_license | struct Something<'a> {
name: &'a str,
}
impl<'a> Drop for Something<'a> {
fn drop(&mut self) {
println!("Something drop {}", self.name);
}
}
fn main() {
println!("Leak example...");
let s1 = Something{name: "one"};
// Drop will not be called for s2 which is the why leak is used.
le... | true |
f41d9a24a0892f0c226c75a35e3767c8488e4c81 | Rust | evookelj/shia-labeouf | /parser.rs | UTF-8 | 2,197 | 2.59375 | 3 | [] | no_license | use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
use std::string::String;
use matrix::Gmatrix;
use display::disp;
use display::clear_screen;
use display::save_ppm;
use draw::draw_lines;
pub fn parse_file(name: &str, transf: &mut Gmatrix, edges: &mut Gmatrix, screen: &mut [[[u32; 3]; 500]; 500]) {
let ... | true |
6601f90a3c057c6d8de5c1083bf3d4b4d7b34526 | Rust | aniketbhatnagar/advent-rust-2019 | /src/day3/mod.rs | UTF-8 | 1,132 | 3.796875 | 4 | [] | no_license | use std::collections::HashSet;
#[derive(PartialEq, Eq, Hash)]
struct Point {
x: u32,
y: u32
}
pub struct Path {
points: HashSet<Point>
}
impl Path {
pub fn add_point(&mut self, x: u32, y: u32) {
self.points.insert(Point {x, y});
}
pub fn point_exists(&self, x: &u32, y: &u32) -> boo... | true |
b91adf84aab55f7fe52640cc484e5f42a8b991bf | Rust | eseraygun/rust-honestintervals | /src/mpfr/impl_float.rs | UTF-8 | 6,923 | 2.671875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | use super::capi::*;
use super::def::Mpfr;
use fp;
use fp::{Float, Sign};
use std::ops::Neg;
impl fp::From<f64> for Mpfr {
#[inline]
fn from_lo(val: f64, precision: usize) -> Self {
Self::from_custom(val, precision, MpfrRnd::Down)
}
#[inline]
fn from_hi(val: f64, precision: usize) -> Self... | true |
7f04dd7430b6d661406054658315004ce555fda2 | Rust | MiyamonY/atcoder | /abc/038/d/01/src/main.rs | UTF-8 | 2,698 | 3.1875 | 3 | [] | no_license | use std::cmp::Ordering;
#[allow(unused_macros)]
macro_rules! scan {
() => {
{
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().to_string()
}
};
(;;) => {
{
let mut line: String = String:... | true |
0d1cf7b55d6ccafd2a476d694a4dd0c1ce76ba0e | Rust | pimox/proxmox | /proxmox/src/sys/timer.rs | UTF-8 | 12,179 | 3.046875 | 3 | [] | no_license | //! POSIX per-process timer interface.
//!
//! This module provides a wrapper around POSIX timers (see `timer_create(2)`) and utilities to
//! setup thread-targeted signaling and signal masks.
use std::mem::MaybeUninit;
use std::time::Duration;
use std::{io, mem};
use libc::{c_int, clockid_t, pid_t};
/// Timers can ... | true |
562ddb87c8e685b0a27c12649ba2cc814d6da21a | Rust | HegemonsHerald/butterbrot_rs | /src/butterbrot.rs | UTF-8 | 1,726 | 2.8125 | 3 | [] | no_license | mod lib;
use lib::*;
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
fn main() {
/* Parse Arguments and setup */
let ( (width, height), (c1, c2), filename, thread_count, (sample_count, iterations, warmup, phase_len), (to,int)) = butterbrot::parse_args(std::env::args().collect());
let ti... | true |
6099e076a66d9b2b804185f1d2e50c8a083728fc | Rust | ritiek/piano-rs | /src/network/receiver.rs | UTF-8 | 1,249 | 2.78125 | 3 | [
"MIT"
] | permissive | use std::time;
use std::net::{SocketAddr, UdpSocket};
use std::io::Result;
use crate::network::types;
#[derive(Debug)]
pub struct Receiver {
pub socket: UdpSocket,
}
impl Receiver {
pub fn new(addr: SocketAddr) -> Result<Receiver> {
let socket = UdpSocket::bind(&addr)?;
Ok(Receiver {
... | true |
867c4b7dc441b82ea315a3bff8751af237f06ad1 | Rust | wfernandes/rust-playground | /guessing_game/src/main.rs | UTF-8 | 1,400 | 4.09375 | 4 | [] | no_license | // these are crates
// Rng is a trait
use rand::Rng;
// Ordering is an enum
use std::cmp::Ordering;
use std::io;
fn main() {
println!("Guess the number!");
let secret_number = rand::thread_rng().gen_range(1, 101);
loop {
// the ! makes this a macro and not a function call
println!("Please... | true |
725d605fd62c2653095b120cefbd6b081f975f8f | Rust | bsumirak/AoC | /AoC2021/src/day16.rs | UTF-8 | 2,953 | 2.734375 | 3 | [] | no_license |
fn inspect_package(msg: &Vec::<bool>, ind: &mut usize, vrsSum: &mut u32) -> u64
{
let mut vrs = 0;
if msg[*ind] {vrs += 4;}
if msg[*ind+1] {vrs += 2;}
if msg[*ind+2] {vrs += 1;}
*vrsSum += vrs;
let mut tp = 0;
if msg[*ind+3] {tp += 4;}
if msg[*ind+4] {tp += 2;}
if msg[*ind+5] {tp += 1;}
if tp == 4
{
... | true |
556fedf5ab0a01e78d4bebf28848cf32c24c3b76 | Rust | guidobotta/Concurrentes-TP1 | /src/model/web_service_connection.rs | UTF-8 | 1,833 | 3.015625 | 3 | [
"MIT"
] | permissive | use super::error::{AppResult, InternalError};
use super::logger::Logger;
use rand::Rng;
use std::ops::Range;
use std::sync::Arc;
use std::{thread, time};
use std_semaphore::Semaphore;
/// Clase que modela un webservice
pub struct WebServiceConnection {
name: String,
permission: Arc<Semaphore>,
work_time_ra... | true |
631510ad15b48532fbfbd77934006e063151a118 | Rust | Logicalshift/flowbetween | /animation/src/editor/stream_animation.rs | UTF-8 | 15,334 | 2.671875 | 3 | [
"Apache-2.0"
] | permissive | use super::stream_layer::*;
use super::stream_animation_core::*;
use crate::traits::*;
use crate::storage::*;
use crate::storage::file_properties::*;
use crate::storage::layer_properties::*;
use ::desync::*;
use flo_stream::*;
use itertools::*;
use futures::prelude::*;
use futures::task::{Poll};
use futures::stream;
... | true |
c9c886a61c89bd5aec1b5ab78f18c1c71aadbce8 | Rust | geom3trik/swash | /src/internal/vorg.rs | UTF-8 | 817 | 3.078125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //! Vertical origin table.
use super::{raw_tag, Bytes, RawTag};
pub const VORG: RawTag = raw_tag(b"VORG");
/// Returns the vertical origin for the specified glyph.
pub fn origin(data: &[u8], vorg: u32, glyph_id: u16) -> Option<i16> {
if vorg == 0 {
return None;
}
let b = Bytes::new(data);
let... | true |
2d284adfe99f030c3089211fcf02ef985ecb62b5 | Rust | janosimas/rust-exercism | /armstrong-numbers/src/lib.rs | UTF-8 | 254 | 3.046875 | 3 | [
"MIT"
] | permissive | pub fn is_armstrong_number(num: u32) -> bool {
let str_num = num.to_string();
let size: u32 = str_num.len() as u32;
let sum = str_num
.chars()
.map(|val| val.to_digit(10).unwrap().pow(size))
.sum();
num == sum
}
| true |
f4126d26e975b587aeb93db5d573b15b2a2f5d7b | Rust | jakutis/directory-hash-rust | /src/read_dir.rs | UTF-8 | 5,439 | 3.515625 | 4 | [] | no_license | use std::fs;
pub struct Paths{dir: String, queue: Vec<Path>}
impl Iterator for Paths {
type Item = Result<String, String>;
fn next(&mut self) -> Option<Self::Item> {
match self.queue.pop() {
None => None,
Some(Path{is_dir: true, path: directory}) => {
match rea... | true |
48f9f029e648883a3653a2c8f8b5d4825f167738 | Rust | david68cu/rust-in-motion-videos | /unit1/module4-primitive-data-types/05-16-arrays/src/main.rs | UTF-8 | 99 | 2.765625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | fn main() {
let a = [0.0, 3.14, -8.7928];
let second = a[1];
println!("{}", second);
}
| true |
c22d40cd0a547d21918cecaa9686bd5b31176da9 | Rust | elusivejoe/huffman-coding | /src/stream_helpers.rs | UTF-8 | 384 | 3 | 3 | [] | no_license | use std::io::{Seek, SeekFrom};
pub fn stream_current_position<T: Seek>(stream: &mut T) -> std::io::Result<u64> {
stream.seek(SeekFrom::Current(0))
}
pub fn stream_length<T: Seek>(stream: &mut T) -> std::io::Result<u64> {
let old_pos = stream_current_position(stream)?;
let len = stream.seek(SeekFrom::End(0... | true |
4096e8128d52f8d549e1bf849e5f90d0ed4ea3e1 | Rust | shellbear/chip8-emu | /src/timers/mod.rs | UTF-8 | 369 | 2.84375 | 3 | [
"MIT"
] | permissive | // More infos here: https://en.wikipedia.org/wiki/CHIP-8#Timers
pub struct Timers {
// A timer used for timing the events of games
pub delay_timer: u8,
// A timer used for sound effects
pub sound_timer: u8,
}
impl Default for Timers {
fn default() -> Self {
Self {
delay_timer:... | true |
b76ff19acb9759dc2563004f63ad2f2624dfecad | Rust | pyjcode/rust-fn-memo | /tests/unsync.rs | UTF-8 | 1,039 | 2.65625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use fn_memo::{unsync, FnMemo};
use recur_fn::*;
fn test_unsync(
memoizer: impl Fn(&dyn DynRecurFn<usize, usize>, &dyn Fn(&dyn FnMemo<usize, usize>)),
) {
let cnt = std::cell::RefCell::new(0);
memoizer(
&recur_fn(|fib, n: usize| {
*cnt.borrow_mut() += 1;
if n <= 1 {
... | true |
c4f385bf0959123f68dc67ff6ae7fbbb8cc7de62 | Rust | olliebatch/postcode_api_rust | /src/api/error.rs | UTF-8 | 991 | 2.6875 | 3 | [] | no_license | use crate::postcode_api::api_client::PostcodeApiErrors;
use tide::StatusCode;
#[derive(Debug, thiserror::Error)]
#[error("{status_code}")]
pub struct ErrorResponse {
status_code: StatusCode,
}
impl ErrorResponse {
fn new(status_code: StatusCode) -> Self {
ErrorResponse { status_code }
}
}
impl Fr... | true |
c2b9019801784c248bbeac00837298ff933eff25 | Rust | rust-lang/rustlings | /exercises/conversions/try_from_into.rs | UTF-8 | 5,360 | 3.890625 | 4 | [
"MIT"
] | permissive | // 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 at
// https://doc.ru... | true |
ffae26358d30ba3836b71d9c73530339acd1c8e8 | Rust | apoelstra/miri | /tests/compile-fail/static_memory_modification3.rs | UTF-8 | 261 | 2.625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::mem::transmute;
#[allow(mutable_transmutes)]
fn main() {
unsafe {
let bs = b"this is a test";
transmute::<&[u8], &mut [u8]>(bs)[4] = 42; //~ ERROR constant evaluation error
//~^ NOTE tried to modify constant memory
}
}
| true |
b38b63454a7e8e33e2a538903a286e6b0a0d892a | Rust | aleksander-mendoza/SolomonoffLib | /native/compiler/src/solomonoff.rs | UTF-8 | 6,644 | 2.515625 | 3 | [
"MIT"
] | permissive | use ghost::Ghost;
use int_seq::IntSeq;
lalrpop_mod!(pub solomonoff_parser); // synthesized by LALRPOP
use regular_operations;
use g::G;
use parser_state::ParserState;
use compilation_error::CompErr;
use lalrpop_util::ParseError;
use lalrpop_util::lexer::Token;
use logger::Logger;
use pipeline::Pipeline;
use std::fs::Fi... | true |
89a01a4c9c4c289c7c86f3ffe9403cb4c96b5f1c | Rust | daball/tilde-table | /refresh-in-rust/src/metamodel/from.rs | UTF-8 | 2,267 | 3.203125 | 3 | [] | no_license |
#[cfg(test)]
mod tests {
use std::error::Error;
use csv::ReaderBuilder;
#[test]
fn test_csv_commas() -> Result<(), Box<dyn Error>> {
let data = "city,country,pop\nBoston,United States,4628910\n";
let mut rdr = ReaderBuilder::new()
.delimiter(b',')
.from_reader(... | true |
cf633b009ff0714f40cabe1fd2917d66c1fa8abe | Rust | s6o/programming-rust | /murderous-artists/src/main.rs | UTF-8 | 2,173 | 3.5625 | 4 | [] | no_license | use std::collections::HashMap;
type Table = HashMap<String, Vec<String>>;
struct Anime {
name: &'static str,
bechdel_pass: bool,
}
fn main() {
println!("Murderous Renaissance Artists");
let mut table = Table::new();
table.insert(
"Gesualdo".to_string(),
vec![
"many madrigals".to_string(),
... | true |
cf099d15bcb2a69f00f887e8985b583c49909d28 | Rust | Abacaxi-Nelson/mama-server | /src/models/place.rs | UTF-8 | 3,259 | 2.890625 | 3 | [
"MIT"
] | permissive | use crate::database::PoolType;
use crate::errors::ApiError;
use crate::handlers::place::{PlaceResponse, PlacesResponse};
use crate::schema::places;
use chrono::{NaiveDateTime, Utc};
use diesel::prelude::*;
use uuid::Uuid;
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Queryable, Identifiable, Insertable)]
... | true |
4e4d639ade6d264f0bbffe933e467e0f5a7a63cc | Rust | EFanZh/LeetCode | /src/problem_1123_lowest_common_ancestor_of_deepest_leaves/mod.rs | UTF-8 | 1,183 | 3.046875 | 3 | [] | no_license | use crate::data_structures::TreeNode;
use std::cell::RefCell;
use std::rc::Rc;
pub mod recursive;
pub trait Solution {
fn lca_deepest_leaves(root: Option<Rc<RefCell<TreeNode>>>) -> Option<Rc<RefCell<TreeNode>>>;
}
#[cfg(test)]
mod tests {
use super::Solution;
use crate::test_utilities;
pub fn run<S:... | true |
7b1e893657608ea08fa72c2adfd5f26d2629c193 | Rust | hawkBaby/workThroughRustInAction | /Chapter3/src/ch3-error.rs | UTF-8 | 402 | 2.765625 | 3 | [] | no_license | static mut ERROR: i32 = 0;
use std::fs::File;
use std::fs::read;
fn main() {
let mut f = File::new("something.txt");
read(f, buffer);
unsafe {
if ERROR != 0 {
panic!("An error has occurred while reading the file ")
}
}
close(f);
unsafe {
if ERROR != 0 {
... | true |
b4cdd0661bd49b7440073b16afc1845305bdad05 | Rust | branan/snazzy | /src/ast.rs | UTF-8 | 1,574 | 3.15625 | 3 | [] | no_license | #[derive(Clone, Debug, PartialEq)]
pub struct Program<'a> {
pub definitions: Vec<Definition<'a>>,
}
#[derive(Clone, Debug, PartialEq)]
pub enum Definition<'a> {
Function(Function<'a>),
Var(Var<'a>),
}
#[derive(Clone, Debug, PartialEq)]
pub struct Var<'a> {
pub address: u32,
pub name: &'a str,
}
#... | true |
1b5179b6668f495000b1659f478131ec4a64f505 | Rust | marco-c/gecko-dev-wordified | /third_party/rust/clap/examples/demo.rs | UTF-8 | 446 | 2.75 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] | permissive | use
clap
:
:
Parser
;
/
/
/
Simple
program
to
greet
a
person
#
[
derive
(
Parser
Debug
)
]
#
[
command
(
author
version
about
long_about
=
None
)
]
struct
Args
{
/
/
/
Name
of
the
person
to
greet
#
[
arg
(
short
long
)
]
name
:
String
/
/
/
Number
of
times
to
greet
#
[
arg
(
short
long
default_value_t
=
1
)
]
count
:
u... | true |
cd3eff6f98455c7701bfa3d132a1fc650b32e380 | Rust | husseinraoouf/juniper-from-schema | /juniper-from-schema-code-gen/src/parse_input.rs | UTF-8 | 1,395 | 2.5625 | 3 | [
"MIT"
] | permissive | use std::path::PathBuf;
use syn::{
self,
parse::{Parse, ParseStream},
Token, Type,
};
#[derive(Debug)]
pub struct GraphqlSchemaFromFileInput {
pub schema_path: PathBuf,
pub error_type: Type,
}
impl Parse for GraphqlSchemaFromFileInput {
fn parse(input: ParseStream) -> syn::Result<Self> {
... | true |
db328eeb87487574d43108e5eeb9f974b825f0cd | Rust | rconaway/groks.rusty_katas | /life_functional/src/life_functional.rs | UTF-8 | 8,901 | 3.515625 | 4 | [] | no_license | use std::collections::HashSet;
#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)]
pub struct Cell {
pub row: isize,
pub col: isize,
}
pub type Board = HashSet<Cell>;
pub fn evolve(board: &Board) -> Board {
board
.into_iter()
.flat_map(|cell| neighbors(*cell))
.filter(|cell| {
... | true |
75c371833a4db1ab18e1f0105e99a1aaea638794 | Rust | Elkien3/minetest-mumble-wrapper | /src/main.rs | UTF-8 | 7,732 | 2.90625 | 3 | [
"MIT"
] | permissive | extern crate mumble_link;
extern crate regex;
use mumble_link::*;
use regex::Regex;
use std::io::{BufRead, BufReader, Read, Write};
use std::process::{Command, Stdio};
use std::path::PathBuf;
// Function to convert errors to error strings so we can return that as a result.
fn errstr<T>(e: T) -> String where T: ToStri... | true |
a27328a319ab8062f7216d51d0e3f1b59d6f2523 | Rust | jmageau/advent_of_code | /src/year_2021/day_5.rs | UTF-8 | 2,003 | 3.296875 | 3 | [] | no_license | use std::collections::BTreeMap;
use parse_display::{Display, FromStr};
aoc_day!(2021, 5);
fn answer_one() -> String {
let lines: Vec<Line> = input().lines().map(|l| l.parse().unwrap()).collect();
let mut points = BTreeMap::new();
for line in lines {
if line.x1 == line.x2 {
let (star... | true |
c82acae2b81dd1af7e3081fb6cfe7f21b466f3ec | Rust | sharnoff/wumpus | /src/main.rs | UTF-8 | 21,399 | 3.203125 | 3 | [
"MIT"
] | permissive | extern crate rand;
use rand::Rng;
use std::io::Write;
use std::process::exit;
use std::env;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum Direction {
North,
South,
East,
West,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum Orientation {
NorthSouth,
EastWest,
}
type Room = [(usize, D... | true |
83e3208ac78e6a8faa247d25691cd8b986575e8e | Rust | aylei/leetcode-rust | /src/solution/s0012_integer_to_roman.rs | UTF-8 | 2,934 | 4.03125 | 4 | [
"Apache-2.0"
] | permissive | /**
* [12] Integer to Roman
*
* Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
*
*
* Symbol Value
* I 1
* V 5
* X 10
* L 50
* C 100
* D 500
* M 1000
*
* For example... | true |
eb094d910f90a139fc87f17104db05acea6b044f | Rust | Skynoodle/gatherr | /src/lib.rs | UTF-8 | 4,755 | 4.1875 | 4 | [] | no_license | //! Helpers to convert iterators of results into results of collections
//! preserving all errors, instead of just the first as `FromIterator` for
//! `Result` does
use std::iter::FromIterator;
/// A newtype implementing FromIterator to collect into a result preserving all
/// error values, instead of just the first a... | true |
d5d9f26462aa3dd7e79f3f5d1438796a237d6670 | Rust | wycats/lalrpop | /lalrpop/src/kernel_set.rs | UTF-8 | 921 | 3 | 3 | [
"Unlicense"
] | permissive | use std::collections::VecDeque;
use std::fmt::Debug;
use std::hash::Hash;
use util::{map, Map};
pub struct KernelSet<I: StateIndex> {
counter: usize,
kernels: VecDeque<I::Kernel>,
map: Map<I::Kernel, I>,
}
pub trait StateIndex: Copy {
type Kernel: Clone + Debug + Hash + Eq;
fn from(c: usize) -> S... | true |
4fec25de6e822bb88bd8af8e948381b7e63604a8 | Rust | nt-com/stm32f401re_rust_examples | /code/04_adc_single_conversion/main.rs | UTF-8 | 1,509 | 2.71875 | 3 | [] | no_license | /// ADC Single Conversion - Blocking Mode
/// LED on Pin A5
/// ADC on Pin A0
/// nt-com
#![no_main]
#![no_std]
use stm32f4::stm32f401;
use cortex_m_rt::entry;
#[allow(unused_extern_crates)]
extern crate panic_halt; // panic handler
fn delay() {
for _i in 0..10000 {
// do nothing.
}
}
#[entry]
fn main() -> ! ... | true |
9ea398da048a4c5e252655d86f5d468b2f7cabff | Rust | RevelationOfTuring/Rust-exercise | /src/error_handling_multiple_error_types_wrapping_errors.rs | UTF-8 | 2,643 | 4.09375 | 4 | [
"Apache-2.0"
] | permissive | /*
把错误装箱这种做法也可以改成把它包裹到你自己的错误类型中。
*/
#[cfg(test)]
mod tests {
use std::num::ParseIntError;
use std::fmt::Formatter;
// 定义Result别名
type Result<T> = std::result::Result<T, DoubleError>;
// 自定义错误类型(枚举)
#[derive(Debug)]
enum DoubleError {
EmptyVec,
// 在这个错误类型中,我们采用 `parse` 的... | true |
76c725e390d75b82e9e9c3e1d51d0b4222f80a47 | Rust | DmitryAstafyev/logviewer | /application/apps/indexer/processor/src/search/extractor.rs | UTF-8 | 3,610 | 2.953125 | 3 | [
"Apache-2.0"
] | permissive | use crate::search::{error::SearchError, filter, filter::SearchFilter};
use grep_regex::RegexMatcher;
use grep_searcher::{sinks::UTF8, Searcher};
use itertools::Itertools;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::{
path::{Path, PathBuf},
str::FromStr,
};
#[derive(Debug, Clone, Serialize, ... | true |
d48c2c28cd98abdf1a958b85c58b3298cbe32363 | Rust | bojand/infer | /src/matchers/image.rs | UTF-8 | 5,851 | 2.765625 | 3 | [
"MIT"
] | permissive | use core::convert::TryInto;
/// Returns whether a buffer is JPEG image data.
pub fn is_jpeg(buf: &[u8]) -> bool {
buf.len() > 2 && buf[0] == 0xFF && buf[1] == 0xD8 && buf[2] == 0xFF
}
/// Returns whether a buffer is jpg2 image data.
pub fn is_jpeg2000(buf: &[u8]) -> bool {
buf.len() > 12
&& buf[0] == ... | true |
cb2c9cb652589375fc78d0947c1b9c1462d275af | Rust | richo/stokepile | /src/dummy_ptp.rs | UTF-8 | 1,381 | 2.578125 | 3 | [] | no_license | pub use failure::Error;
#[derive(Debug)]
pub struct PtpCamera<'c> {
_phantom: &'c std::marker::PhantomData<()>,
}
impl<'c> PtpCamera<'c> {
pub fn delete_object(&mut self, _handle: u32, _1: Option<()>) -> Result<(), Error> {
unimplemented!("You shouldn't be calling methods from dummy_ptp");
}
... | true |
3db7c10c25ff33fad54d764020ccfc35c9e14271 | Rust | joshuadmasterson/codealong | /codealong/src/repo_config.rs | UTF-8 | 3,243 | 3.0625 | 3 | [
"MIT"
] | permissive | use std::fs::File;
use std::path::Path;
use git2::Repository;
use crate::config::Config;
use crate::error::*;
use crate::repo_info::RepoInfo;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RepoConfig {
#[serde(flatten)]
pub config: Config,
#[serde(default, flatten)]
pub repo: ... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.