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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
dd4ae21c4126da3f6de03034fad8daa126c41639 | Rust | tokio-rs/tokio | /tokio/tests/process_issue_2174.rs | UTF-8 | 1,367 | 2.90625 | 3 | [
"MIT"
] | permissive | #![cfg(feature = "process")]
#![warn(rust_2018_idioms)]
// This test reveals a difference in behavior of kqueue on FreeBSD. When the
// reader disconnects, there does not seem to be an `EVFILT_WRITE` filter that
// is returned.
//
// It is expected that `EVFILT_WRITE` would be returned with either the
// `EV_EOF` or `E... | true |
1e280176b1ffba769a1fc6c39e95eb46521b6fda | Rust | rojo-rbx/rbx-dom | /rbx_types/src/lister.rs | UTF-8 | 414 | 3.5 | 4 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::fmt;
/// Small utility to write formatting functions for lists of things.
pub(crate) struct Lister {
first: bool,
}
impl Lister {
pub fn new() -> Self {
Self { first: true }
}
pub fn write(&mut self, out: &mut fmt::Formatter, label: impl fmt::Display) -> fmt::Result {
if !sel... | true |
8bacbf45edbb0bdc2314c664ddfe0b5df2d2167c | Rust | stsewd/programming-problems-rust | /src/bin/count_div.rs | UTF-8 | 757 | 3.390625 | 3 | [
"MIT"
] | permissive | // https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/count-divisors/
use std::io::{self, BufRead};
fn solve(a: i32, b: i32, c: i32) -> i32 {
(a..=b).filter(|n| n % c == 0).count() as i32
}
fn main() {
let stdin = io::stdin();
let mut it... | true |
7c1fa02e2cb55e789adc757db6706d526b55a40a | Rust | mindstorms6/helium-wallet-rs | /src/traits/read_write.rs | UTF-8 | 634 | 2.609375 | 3 | [
"Apache-2.0"
] | permissive | use crate::{
keypair::{PublicKey, PUBLIC_KEY_LENGTH},
result::Result,
};
use io::{Read, Write};
use std::io;
pub trait ReadWrite {
fn read(reader: &mut dyn Read) -> Result<Self>
where
Self: std::marker::Sized;
fn write(&self, writer: &mut dyn Write) -> Result;
}
impl ReadWrite for PublicKe... | true |
e475866552c1433b4efdf51d6e513af680ca8713 | Rust | clay-rs/clay-core | /src/shape/shape.rs | UTF-8 | 1,148 | 2.953125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | use crate::{
prelude::*,
map::Map,
shape::ShapeMapper,
material::Material,
object::Covered,
};
/// Shape of an object.
///
/// It defines the search of the point where ray intersects this shape.
pub trait Shape: Pack + Instance<ShapeClass> {
/// Creates a new shape by applying some kind of m... | true |
534592334423eaea72ea1e5ae2c3923b28abfbf2 | Rust | iCodeIN/lox | /src/io/stl/write.rs | UTF-8 | 12,656 | 3.25 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] | permissive | use std::{
cmp,
convert::TryInto,
io::{self, Write},
};
use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
use cgmath::prelude::*;
use crate::{
prelude::*,
io::{PropKind, Error, ErrorKind},
};
use super::{Encoding, RawTriangle};
// ----------------------------------------------------------... | true |
6c1016cb917a505c5c91ae5c5720991e6a6eb14a | Rust | hideakitai/SketchesSystem | /rust/examples/static_local_variable_thread_local.rs | UTF-8 | 378 | 3.046875 | 3 | [] | no_license | use std::cell::RefCell;
fn print_and_count_number() {
thread_local!(
pub static NUMBER_MUT: RefCell<u32> = RefCell::new(5u32)
);
NUMBER_MUT.with(|number| {
let mut n = number.borrow_mut();
println!("{}", *n);
*n += 1;
})
}
fn main() {
print_and_count_number();
... | true |
b6845ff23ab56d824f051f3f368db8c302c74d09 | Rust | offscale/cdd-ctl | /src/project/variable.rs | UTF-8 | 1,234 | 3.390625 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct Variable {
pub name: String,
#[serde(rename = "type")]
pub variable_type: VariableType,
pub optional: bool,
pub value: Option<String>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Seriali... | true |
7b245a37e0304cd2af4c1c17aeaa7c01b479e62f | Rust | PriTanir/adder1 | /tests/examples.rs | UTF-8 | 2,136 | 3.015625 | 3 | [] | no_license | use snake::runner::compile_and_run_file;
macro_rules! mk_test {
($test_name:ident, $file_name:expr, $expected_output:expr) => {
#[test]
fn $test_name() -> std::io::Result<()> {
test_example_file($file_name, $expected_output)
}
}
}
macro_rules! mk_fail_test {
($test_name:ident, $file_name:expr, $e... | true |
3567a692df6da5d253554dd1d7afd76ec1893432 | Rust | beachcitiessoftware/rtcp | /src/full_intra_request/mod.rs | UTF-8 | 4,147 | 2.8125 | 3 | [
"MIT"
] | permissive | mod full_intra_request_test;
use byteorder::{BigEndian, ByteOrder};
use bytes::BytesMut;
use std::fmt;
use crate::{errors::Error, header, header::Header, packet::Packet, util::get_padding};
/// A FIREntry is a (ssrc, seqno) pair, as carried by FullIntraRequest.
#[derive(Debug, PartialEq, Default, Clone)]
pub struct ... | true |
da138a307ed7ea853917b29e0f80ecfc48102e7d | Rust | pkusensei/adventofcode2020 | /day20/src/main.rs | UTF-8 | 5,082 | 3.109375 | 3 | [
"MIT"
] | permissive | use std::collections::HashMap;
use itertools::Itertools;
type Error = Box<dyn std::error::Error>;
const WIDTH: usize = 10;
const HEIGHT: usize = 10;
fn main() {
let input = include_str!("..\\input.txt");
let tiles = read(&input, "\r\n\r\n").unwrap();
let (corners, _tiles) = find_corners(tiles);
asse... | true |
19c4649bb6d985685e5194b21a45804fe9805bb1 | Rust | cbreeden/font-shape | /src/font.rs | UTF-8 | 5,952 | 2.796875 | 3 | [] | no_license | use decode::{Error, Result, SizedTable, Table, Primitive, ReadPrimitive, ReadTable};
use decode::primitives::{Tag, Ignored};
use table::TaggedTable;
use table::name::Name;
use table::hmtx::Hmtx;
use table::maxp::Maxp;
use table::hhea::Hhea;
#[derive(Debug)]
pub enum Version {
OpenType,
TrueType,
}
impl Primi... | true |
0112973510f04e440ba56c22fae94d6b6a55654f | Rust | utam0k/rjvm | /src/class/constant_pool/name_and_type_info.rs | UTF-8 | 872 | 2.703125 | 3 | [
"MIT"
] | permissive | use std::fmt;
use std::io::Cursor;
use byteorder::{BigEndian, ReadBytesExt};
use crate::class::ReaderResult;
// https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.6
#[repr(C)]
#[derive(Clone, Copy)]
pub struct NameAndTypeInfo {
pub name_index: u16,
pub descriptor_index: u16,
}
impl Name... | true |
4ef118200b6c76df24129c6b631c4df184e60296 | Rust | boa-dev/boa | /boa_parser/src/parser/tests/format/mod.rs | UTF-8 | 1,722 | 3.15625 | 3 | [
"MIT",
"Unlicense"
] | permissive | mod declaration;
mod expression;
mod function;
mod statement;
/// This parses the given source code, and then makes sure that
/// the resulting `StatementList` is formatted in the same manner
/// as the source code. This is expected to have a preceding
/// newline.
///
/// This is a utility function for tests. It was ... | true |
23cbad1b09a8dc63672898b989038f4b911a3857 | Rust | andete/atsam4lc8c | /src/iisc/imr/mod.rs | UTF-8 | 6,498 | 2.734375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | #[doc = r" Value read from the register"]
pub struct R {
bits: u32,
}
impl super::IMR {
#[doc = r" Reads the contents of the register"]
#[inline]
pub fn read(&self) -> R {
R {
bits: self.register.get(),
}
}
}
#[doc = "Possible values of the field `RXRDY`"]
#[derive(Clone,... | true |
7907f05a98c2689a3b23d39207d6aad7a95ed8f2 | Rust | informalsystems/jsonatr | /tests/simple.rs | UTF-8 | 1,293 | 2.6875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | use jsonatr::transformer::*;
use serde_json::Value;
use std::process::Command;
fn test_expect(file: &str, expect: &str) {
let input = std::fs::read_to_string(file).unwrap();
let mut spec = Transformer::new(&input, file).unwrap();
let res = spec.transform(&Value::Null).unwrap();
assert_eq!(res, expect)
... | true |
82f4e79bff7f26510afcc1ba138bc260ecb5bc72 | Rust | fratorgano/advent_of_code_2020 | /day04/src/lib.rs | UTF-8 | 7,042 | 3.359375 | 3 | [] | no_license | //Please don't even bother to look at this code, it's a real mess, I hate parsing inputs with Rust
pub struct Passport{
pub byr: usize, // >=1920 <=2002
pub iyr: usize, // >=2010 <=2020
pub eyr: usize, // >=2020 <=2030
pub hgt: String, // number + cm/inch
pub hcl: String, // #FFFFFF
pub ecl: St... | true |
26b76b95e800f3680d2c3c761e404eec025dc110 | Rust | jagill/magog-rust | /src/planar/primitives/triangle.rs | UTF-8 | 1,784 | 3.34375 | 3 | [] | no_license | use crate::planar::primitives::Position;
use crate::Coordinate;
#[derive(Copy, Clone, Debug)]
pub struct Triangle<C: Coordinate>(pub Position<C>, pub Position<C>, pub Position<C>);
impl<C: Coordinate> Triangle<C> {
pub fn to_array(&self) -> [Position<C>; 3] {
[self.0, self.1, self.2]
}
}
// (P, P, P)... | true |
4f45f1d3247e0b81b14977c82d63d938ed80f999 | Rust | apr-xaml/rust | /projects/tutorial/nItPiazzaTutorial/nItPiazzaTutorial/nItPiazzaTutorial/src/_learning_tests_2.rs | UTF-8 | 662 | 3.375 | 3 | [] | no_license | #![allow(non_snake_case)]
#![cfg(test)]
fn _returnSameI32(x: i32) -> i32 {
x
}
fn _returnDifferentI32(x: i32) -> i32 {
1
}
fn _returnSameString()
{
}
#[test]
fn Can_read_variable_in_inner_block() {
let x: i32 = 1;
{
let x2 = x;
assert_eq!(x2, x);
}
assert_eq!(x, 1);
}... | true |
dacfbab9fea626dbb320686d7e5fe786aeeeab1c | Rust | jcaplan/zellij | /src/common/input/handler.rs | UTF-8 | 15,414 | 2.703125 | 3 | [
"MIT"
] | permissive | //! Main input logic.
use super::actions::Action;
use super::keybinds::get_default_keybinds;
use crate::common::{update_state, AppInstruction, AppState, SenderWithContext, OPENCALLS};
use crate::errors::ContextType;
use crate::os_input_output::OsApi;
use crate::pty_bus::PtyInstruction;
use crate::screen::ScreenInstruc... | true |
0aa98e7c417658b71ed14501786cd350ccfc1887 | Rust | GoTamura/ray | /src/utils.rs | UTF-8 | 2,585 | 2.90625 | 3 | [
"MIT"
] | permissive | use nalgebra::clamp;
pub type Vec3 = nalgebra::Vector3<f64>;
pub type Point3 = nalgebra::Point3<f64>;
pub type Point2 = nalgebra::Point2<f64>;
pub type Color = Vec3;
pub fn degrees_to_radians(degrees: f64) -> f64 {
degrees * std::f64::consts::PI / 180.0
}
pub fn random_double(min: f64, max: f64) -> f6... | true |
dda263f5795d037e74d9e92eb392f06a5c051d25 | Rust | dignifiedquire/rust-accumulators | /src/hash.rs | UTF-8 | 3,556 | 3.15625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use blake2::Digest;
use byteorder::{BigEndian, WriteBytesExt};
use generic_array::ArrayLength;
use num_bigint::prime::probably_prime;
use num_bigint::BigUint;
use num_integer::Integer;
// When the proofs are made non-interactive, using the
// Fiat-Shamir heuristic the challenge is generated by hashing the previous tra... | true |
e76fe144ee2cd4df25bf6e47604dea2d5f5149fd | Rust | ntgussoni/asciidoctor-rust | /src/main.rs | UTF-8 | 1,785 | 3.34375 | 3 | [] | no_license | use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;
fn main() {
// File hosts must exist in current path before this produces output
if let Ok(lines) = read_lines("./test.adoc") {
// Consumes the iterator, returns an (Optional) String
for (row, line) in lines.enumerate() {
if let Ok(ip) = li... | true |
c355bc262d7c47ec82d6a2defd8f1a730ff63a9e | Rust | pyk/hello-rust | /second-edition/functions/src/main.rs | UTF-8 | 402 | 3.59375 | 4 | [] | no_license | fn another_function() {
println!("another_function function");
}
fn params(x: i32, y: i32) {
println!("The value of x is: {}", x);
println!("The value of y is: {}", y);
}
fn return_value(x: i32) -> i32 {
return x + 5;
}
fn main() {
println!("main function");
another_function();
params(2, ... | true |
3d704cec218f0f01d5246c775a6edbdb6f784534 | Rust | knarfytrebil/lpd | /testenv/src/home.rs | UTF-8 | 4,637 | 3.234375 | 3 | [
"Apache-2.0"
] | permissive | use std::path::Path;
use std::path::PathBuf;
use std::io;
use std::fs;
/// Abstracts directory containing keys
#[derive(Debug)]
pub struct Home {
name: String,
// should directory with files be deleted in the end
// when Home struct is dropped
cleanup_files: bool
}
impl Home {
fn sandbox() -> &'s... | true |
2af9077339a0ea0b35c421ec111763befba17c51 | Rust | saritag2020/rules_rust | /tools/rustfmt/srcs/lib.rs | UTF-8 | 2,430 | 3.09375 | 3 | [
"Apache-2.0"
] | permissive | use std::env;
use std::fs;
use std::path::{Path, PathBuf};
/// The expected extension of rustfmt manifest files generated by `rustfmt_aspect`.
pub const RUSTFMT_MANIFEST_EXTENSION: &'static str = "rustfmt";
/// Generate an absolute path to a file without resolving symlinks
fn absolutify_existing<T: AsRef<Path>>(path:... | true |
3e7c9e0c8a494f24475a988a432da4fa47c7edaa | Rust | nico-abram/bottom-rs-web | /src/lib.rs | UTF-8 | 2,802 | 2.5625 | 3 | [] | no_license | use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
pub mod bottom;
// When the `wee_alloc` feature is enabled, this uses `wee_alloc` as the global
// allocator.
//
// If you don't want to use `wee_alloc`, you can safely delete this.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_all... | true |
460862a8ebea748bb0c0c37da289120e2f4c121b | Rust | bolshchikov/adventofcode-solutions | /2017/day_8/src/instruction.rs | UTF-8 | 1,464 | 3.6875 | 4 | [
"MIT"
] | permissive | #[derive(Debug)]
pub struct Condition {
pub register: String,
pub op: String,
pub value: i32,
}
#[derive(Debug)]
pub struct Instruction {
pub register: String,
pub action: String,
pub value: i32,
pub condition: Condition,
}
impl Instruction {
pub fn new(line: &String) -> Instruction {
... | true |
98f2386820f98c71a5b1ee032c23b882636c8de9 | Rust | bluenote10/rust-array-stump | /benchmarks/src/alternatives/slot_array.rs | UTF-8 | 17,288 | 3.109375 | 3 | [
"MIT"
] | permissive | use std::cmp::Ordering;
use std::iter;
pub struct SlotArray<T, C>
where
C: Fn(&T, &T) -> Ordering,
{
spacing: usize,
comparator: C,
data_raw: Vec<Option<T>>,
num_elements: usize,
}
#[allow(dead_code)]
impl<T, C> SlotArray<T, C>
where
C: Fn(&T, &T) -> Ordering,
T: Clone + std::fmt::Debug,
{... | true |
24b42e969d95b10c8f57e6457510bffbafb89aeb | Rust | mjz19910/rust | /src/test/run-pass/utf8_chars.rs | UTF-8 | 1,037 | 2.765625 | 3 | [
"BSD-1-Clause",
"LicenseRef-scancode-other-permissive",
"LicenseRef-scancode-public-domain",
"MIT",
"BSD-2-Clause",
"bzip2-1.0.6",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | // xfail-stage0
// xfail-stage1
// xfail-stage2
use std;
import std::_str;
import std::_vec;
import std::io;
fn main() {
// Chars of 1, 2, 3, and 4 bytes
let vec[char] chs = vec('e', 'é', '€', 0x10000 as char);
let str s = _str::from_chars(chs);
assert (_str::byte_len(s) == 10u);
assert (_str::char_len(s) =... | true |
f75dde55174d5f7355fc08174a240c13d34d92a7 | Rust | allwefantasy/mlsql-store | /src/controller/store_controller.rs | UTF-8 | 2,276 | 2.53125 | 3 | [] | no_license | use rocket::response::{content, Stream, NamedFile, Responder};
use rocket::{post, get, State, Request, Response};
use rocket::request::{FromForm, Form};
use rocket::http::Status;
use serde::{Deserialize, Serialize};
use mysql as my;
use std::sync::mpsc::Sender;
use std::io;
use std::fs::File;
use serde_json;
use std::p... | true |
38b34b263962232548966a140aec6498ab20a9c3 | Rust | amoura/raytracer | /src/main.rs | UTF-8 | 1,456 | 3.09375 | 3 | [
"MIT"
] | permissive | use raytracer::canvas::Canvas;
use raytracer::canvas::Colour;
use raytracer::maths::{Matrix4,Matrix3,almost_same};
fn paint_square(c: &mut Canvas, col: Colour, x0: usize, y0: usize, x1: usize, y1: usize) {
for y in y0..y1 {
for x in x0..x1 {
c.write_pixel(x, y, col);
}
}
}
fn main(... | true |
1905ebdf06747b02ee05d2d5eef8f47600ab7e39 | Rust | jayoharedee/sawtooth-seth | /cli/src/cli/permissions.rs | UTF-8 | 3,836 | 2.828125 | 3 | [
"Apache-2.0",
"CC-BY-4.0"
] | permissive | /*
* Copyright 2018 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agre... | true |
7f23d07a61e2f41bbd321cd04c968bba8b8a5852 | Rust | rust-lang/rust | /src/tools/clippy/tests/ui/iter_on_empty_collections.rs | UTF-8 | 1,735 | 3.328125 | 3 | [
"Apache-2.0",
"MIT",
"LLVM-exception",
"NCSA",
"BSD-2-Clause",
"LicenseRef-scancode-unicode",
"LicenseRef-scancode-other-permissive"
] | permissive | #![warn(clippy::iter_on_empty_collections)]
#![allow(clippy::iter_next_slice, clippy::redundant_clone)]
fn array() {
assert_eq!([].into_iter().next(), Option::<i32>::None);
assert_eq!([].iter_mut().next(), Option::<&mut i32>::None);
assert_eq!([].iter().next(), Option::<&i32>::None);
assert_eq!(None.in... | true |
d1c224fbbabbee3b97ba10e7b04f12a4182b8ce5 | Rust | earthengine/Lincoln | /lincoln_common/src/permutation.rs | UTF-8 | 6,431 | 3.265625 | 3 | [
"MIT"
] | permissive | use core::fmt::{Display, Error, Formatter};
use core::str::FromStr;
use smallvec::SmallVec;
/// A trait to treat some suitable type to a permutation, without consuming
pub trait AsPermutation {
//Return a permutation from a shared reference
fn as_permutation(&self) -> Result<Permutation, failure::Error>;
}
pu... | true |
215dd43b36b70fc0dd8d1e37bf4c195e5bafdf17 | Rust | rome/tools | /crates/rome_js_analyze/src/analyzers/a11y/use_valid_anchor.rs | UTF-8 | 7,528 | 3.390625 | 3 | [
"MIT"
] | permissive | use rome_analyze::context::RuleContext;
use rome_analyze::{declare_rule, Ast, Rule, RuleDiagnostic};
use rome_console::{markup, MarkupBuf};
use rome_js_syntax::jsx_ext::AnyJsxElement;
use rome_rowan::{AstNode, TextRange};
declare_rule! {
/// Enforce that all anchors are valid, and they are navigable elements.
... | true |
f59de6f78438fa46300c976e5cb956b5e73fcbd2 | Rust | iomeone/KISS-multiplayer | /kissmp-server/src/vehicle/electrics.rs | UTF-8 | 1,065 | 2.578125 | 3 | [
"Apache-2.0"
] | permissive | use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct ElectricsUndefined {
pub vehicle_id: u32,
pub diff: std::collections::HashMap<String, f32>,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct Electrics {
pub vehicle_id: u32,
... | true |
21ee3d6214dd37ade9f7c923e39caa7e78ff42d6 | Rust | jkbstrmen/snark-tool | /src/service/constructions/dot_product.rs | UTF-8 | 6,254 | 2.96875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use crate::graph::edge::Edge;
use crate::graph::graph::{Graph, GraphConstructor};
use crate::graph::undirected::edge::UndirectedEdge;
use crate::graph::vertex::Vertex;
use crate::service::component_analysis::edge_pairs::PairsOfNonAdjacentEdges;
use crate::service::component_analysis::vertex_pairs::PairsOfAdjacentVertic... | true |
87bee7a065410ff7337bb8b56372833a827c1289 | Rust | imishinist/rval | /src/pace/rate.rs | UTF-8 | 1,776 | 3.234375 | 3 | [] | no_license | use std::ops::Sub;
use std::time::Duration;
use crate::pace::{PaceState, Pacer};
pub struct Rate {
freq: u128,
per: Duration,
}
impl Rate {
pub fn new(freq: u128, per: Duration) -> Rate {
assert!(freq > 0);
assert!(per > Duration::from_secs(0));
Rate { freq, per }
}
}
impl Pa... | true |
bf9e21996fd48cf7ca1e6381c4eb8810d8cca812 | Rust | rotwatsb/code_kata | /src/hackerrank/the_grid_search.rs | UTF-8 | 1,439 | 3 | 3 | [] | no_license | use std::io;
pub fn grid_search() {
let mut t_str: String = String::new();
io::stdin().read_line(&mut t_str).unwrap();
for _ in 0u32..t_str.trim().parse().unwrap() {
let g: Vec<String> = read_matrix();
let p: Vec<String> = read_matrix();
if contains(&g, &p) { println!("YES"); ... | true |
b526f388202100f977ffb276778f4096cb3e5c49 | Rust | montanonic/computour | /src/lc3/instructions.rs | UTF-8 | 784 | 2.5625 | 3 | [] | no_license | //! Via https://github.com/erfur/lc3-vm-rust/blob/master/src/instruction.rs
pub type Offset = u16;
pub type Imm = u16;
pub type TrapVector = u8;
pub type Flag = bool;
pub type Register = usize;
#[derive(Debug, Clone, Copy)]
pub enum Instruction {
AddReg(Register, Register, Register),
AddImm(Register, Register... | true |
575135b19538325739addd438892c854a035e1fb | Rust | Wint3rmute/tiler | /src/size_settings.rs | UTF-8 | 371 | 3.015625 | 3 | [] | no_license | use std::env::args;
pub enum SizeSettings {
BigGaps,
SmallGaps,
}
pub fn get_size_settings() -> SizeSettings {
let mut result = SizeSettings::BigGaps;
match args().nth(1) {
Some(value) => {
if value == "small" {
result = SizeSettings::SmallGaps;
}
... | true |
3b2f7db5334f670813523f5860fec51d2f8e457f | Rust | srijs/rpdf | /rpdf_graphics/src/font/loaded.rs | UTF-8 | 674 | 2.875 | 3 | [
"MIT"
] | permissive | use std::sync::Arc;
use failure::Fallible;
pub struct LoadedFont {
inner: font_kit::loaders::default::Font,
}
impl LoadedFont {
pub fn from_bytes(bytes: Arc<Vec<u8>>) -> Fallible<Self> {
Ok(LoadedFont {
inner: font_kit::loaders::default::Font::from_bytes(bytes, 0)?,
})
}
... | true |
c97e2bb60880c86755a299c5c6bca3545eecf558 | Rust | vulkano-rs/vulkano | /vulkano/src/command_buffer/allocator.rs | UTF-8 | 25,786 | 2.78125 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | // Copyright (c) 2016 The vulkano developers
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>,
// at your option. All files in the project carrying such
// notice may not be ... | true |
c76abc31a171133e6894eeeb4ba350158f33b339 | Rust | 19h/rustun | /src/server/base.rs | UTF-8 | 5,243 | 2.578125 | 3 | [
"MIT"
] | permissive | use std::net::SocketAddr;
use fibers::{Spawn, BoxSpawn};
use fibers::sync::mpsc;
use futures::{Future, Poll, Async, Stream, AsyncSink};
use trackable::error::ErrorKindExt;
use {Result, Error, HandleMessage, ErrorKind};
use message::{Class, RawMessage};
use transport::Transport;
use super::IndicationSender;
/// Base S... | true |
25b77282407406a24c9fff5699975fa96f2be662 | Rust | davidpdrsn/robin | /robin/src/job.rs | UTF-8 | 3,133 | 3.25 | 3 | [
"MIT"
] | permissive | extern crate serde_json;
use connection::Connection;
use error::{Error, RobinResult};
use queue_adapters::{JobQueue, QueueIdentifier, RetryCount};
use serde::{Deserialize, Serialize};
use std;
/// The result type returned when performing jobs
pub type JobResult = Result<(), Box<std::error::Error>>;
/// A type that h... | true |
18a5b02a71f5b4afc533c3fa1e8beaaa5533d013 | Rust | Havvy/open-factory | /crates/test-factory-a/src/factory.rs | UTF-8 | 18,884 | 2.5625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use bevy::math::Vec3Swizzles;
use bevy::prelude::*;
use open_factory::item_stack::ItemStackQuanity;
use open_factory::registry::Table;
use open_factory::producer::{Producer, ProductionStatus};
use open_factory::kinds::RecipeKind;
use open_factory::connector::{Connector, ConnectorStatus};
use crate::ui::Action;
use cra... | true |
cd4dee999822afc635795430eff7aa7d84cbd528 | Rust | danielq987/minigrep | /src/lib.rs | UTF-8 | 2,978 | 3.390625 | 3 | [] | no_license | use std::{env, error, fs};
pub fn run(config: Config) -> Result<(), Box<dyn error::Error>> {
let contents = fs::read_to_string(config.filename)?;
for line in search(&config.query, &contents, config.is_case_sensitive) {
println!("{}", line);
}
Ok(())
}
pub fn search<'a>(query: &str, contents:... | true |
74102b6e1b488e57c796b411d32c204e450e999a | Rust | jihchi/nanachi | /src/path_data_notation/mod.rs | UTF-8 | 13,204 | 3 | 3 | [
"MIT"
] | permissive | mod tokenize;
use std::{iter::Peekable, str::Chars};
use tokenize::{Tokenize, Token};
use crate::point::Point;
use crate::path::Path;
use crate::path_builder::PathBuilder;
enum LastControlPoint {
Quad(Point),
Cubic(Point),
None
}
/// Parse [SVG path notation](https://developer.mozilla.org/en-US/docs/Web/... | true |
b382e9c1c11f49c28e4a26d0a764037395785095 | Rust | diesel-rs/diesel | /diesel_migrations/migrations_macros/src/util.rs | UTF-8 | 1,341 | 3.03125 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use syn::*;
pub fn str_value_of_meta_item(item: &Meta, name: &str) -> String {
match *item {
Meta::NameValue(MetaNameValue {
lit: Lit::Str(ref value),
..
}) => value.value(),
_ => panic!(
r#"`{}` must be in the form `#[{}="something"]`"#,
name... | true |
b307d39c7a1fbbd76a54499812775182bb3e4855 | Rust | gerardabello/toydb | /kv_store/src/hashmap_mem_table.rs | UTF-8 | 1,719 | 3.140625 | 3 | [] | no_license | use crate::domain;
use std::collections::HashMap;
use std::hash::Hash;
#[derive(Debug)]
pub struct HashMapMemTable<Tkey: Ord + Sized + Eq + Hash , Tvalue: Sized> {
hashmap: HashMap<Tkey, Tvalue>,
}
impl<Tkey: Ord + Sized + Eq + Hash, Tvalue: Sized> HashMapMemTable<Tkey, Tvalue> {
fn new() -> HashMapMemTable<T... | true |
63e32466472bcfef2143158db500298fb6d74cc7 | Rust | RustAudio/rust-lv2 | /atom/src/atoms/chunk.rs | UTF-8 | 3,623 | 3.25 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! An atom containing memory of undefined type.
//!
//! This contents of this atom is considered as a simple blob of data. It used, for example, by the host to transmit the size of a writable atom port. Since it is so simple, it does not need a reading or writing parameter.
//!
//! # Example
//! ```
//! use lv2_core::... | true |
be8130c7a9268577fcd3b0fac722966b0042c21d | Rust | TangliziGit/leetcode | /rust/offer14-1.rs | UTF-8 | 319 | 3.015625 | 3 | [] | no_license | impl Solution {
pub fn cutting_rope(n: i32) -> i32 {
let mut ans = 1;
for m in 2..n {
ans = ans.max(mul(n, m));
}
ans
}
}
fn mul(n: i32, m: i32) -> i32 {
let avg = n / m;
let rest = n - avg * m;
(avg+1).pow(rest as u32) * avg.pow((m - rest) as u32)
}
| true |
d8dcafde8e01fff67fd2358fdec125d8e782fa4c | Rust | str4d/ire | /src/util.rs | UTF-8 | 4,291 | 3.3125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | //! Helper functions
use bloom_filter_rs::{BloomFilter, Murmur3};
use cookie_factory::GenError;
use core::fmt;
use std::iter::repeat;
use std::mem;
pub fn serialize<S>(serializer: S) -> Vec<u8>
where
S: Fn((&mut [u8], usize)) -> Result<(&mut [u8], usize), GenError>,
{
let mut buf = vec![];
loop {
... | true |
19a0f9738961e8062050c6686a412112ba1a69dc | Rust | vishalsodani/bracket_parse | /src/lib.rs | UTF-8 | 10,724 | 3.78125 | 4 | [] | no_license | //! # Bracket Parse
//!
//! A Utility for parsing Bracketed lists and sets of strings.
//!
//! It is a relatively lazy way of parsing items from a bracketed string,
//!
//! "hello(peter,dave)" is easy for it to handle, as are nested brackets.
//!
//! The above will result in something like
//!
//! >Branch[Leaf("hello... | true |
a8b0c748804e0bf70cd89d1fb76d8e5bec52b0b7 | Rust | qeda/qeda-cli | /src/drawing/attribute.rs | UTF-8 | 1,868 | 3.421875 | 3 | [
"MIT"
] | permissive | use super::prelude::*;
use super::{Layer, Point, Transform, Transformation};
#[derive(Clone, Default, Debug)]
pub struct Attribute {
pub id: String,
pub value: String,
pub origin: Point,
pub font_size: f64,
pub line_width: f64,
pub halign: HAlign,
pub valign: VAlign,
pub orientation: Or... | true |
47f6df91245a46751d6261e14017168adbc6114e | Rust | RazrFalcon/tiny-skia | /src/path64/line_cubic_intersections.rs | UTF-8 | 4,405 | 3.03125 | 3 | [
"BSD-3-Clause"
] | permissive | // Copyright 2012 Google Inc.
// Copyright 2020 Yevhenii Reizner
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/*
Find the intersection of a line and cubic by solving for valid t values.
Analogous to line-quadratic intersection, solve line-cubic intersectio... | true |
22a4f8f295f67ec9ff88b5dedad42e842f5b9089 | Rust | johnpmayer/quicksilver-utils | /quicksilver-utils-async/src/time.rs | UTF-8 | 774 | 3.28125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"MIT"
] | permissive | //! # time
//!
//! `time` just contains `sleep_ms` right not, but is the place
//! where I'd put something like a timer or something more
//! sophistocated like periodic scheduler with a "maximum fps"
//! governed periodic invocation
#[cfg(not(target_arch = "wasm32"))]
use crate::desktop::time;
#[cfg(all(target_arch ... | true |
7c421d6943d4d00879e8241105421549356b96d3 | Rust | magiclen/passwords | /tests/generator.rs | UTF-8 | 14,611 | 3.3125 | 3 | [
"MIT"
] | permissive | use passwords::PasswordGenerator;
use regex::Regex;
const PASSWORD_COUNT: usize = 5000;
#[test]
fn random() {
{
let pg = PasswordGenerator::new();
{
let result_1 = pg.generate_one().unwrap();
let result_2 = pg.generate_one().unwrap();
assert_ne!(result_1, resu... | true |
67305a7a5e05137ad4e20a79452ba308301590b1 | Rust | CNife/leetcode | /rust/finished/src/subtract_the_product_and_sum_of_digits_of_an_integer.rs | UTF-8 | 448 | 3.78125 | 4 | [] | no_license | pub fn subtract_product_and_sum(mut n: i32) -> i32 {
let mut digits = Vec::with_capacity(10);
while n != 0 {
digits.push(n % 10);
n /= 10;
}
let product: i32 = digits.iter().product();
let sum: i32 = digits.into_iter().sum();
product - sum
}
#[test]
fn test() {
let cases = v... | true |
2818e8db8e7ab7a952a76a3ab6a2d911cb925c45 | Rust | mklein994/weather | /src/color.rs | UTF-8 | 2,115 | 3.796875 | 4 | [] | no_license | use serde::{de, Deserialize, Deserializer};
use std::str::FromStr;
#[derive(Eq, PartialEq, Copy, Clone, Debug, Default)]
pub struct Color {
pub red: u8,
pub green: u8,
pub blue: u8,
pub alpha: u8,
}
impl Color {
pub fn hex(self) -> String {
format!(
"#{:02x}{:02x}{:02x}{:02x}",... | true |
142c3b2f16f94d27189ef943cd31bf85be0a3bb9 | Rust | LambdaP/Maze.rs | /src/maze_display/mod.rs | UTF-8 | 3,652 | 2.9375 | 3 | [] | no_license | extern crate image;
use maze;
use std::rand;
use self::image::{
ImageBuf,
Rgb,
};
use std::io::File;
static square_size : uint = 10;
static grid_size : uint = maze::grid_size;
#[deriving(PartialEq,Rand,Show)]
enum Color {
Lime,
Pacific,
Purple,
Stonewall,
Zinger,
Pumpkin,
Tareum,... | true |
609bd501dd67802b3a0c5896c1c999fc961cd31d | Rust | xiaojay/rusty | /aes256gcm/src/main.rs | UTF-8 | 688 | 2.625 | 3 | [] | no_license | use ring::aead;
use base64;
use rand::{thread_rng, Rng};
fn main() {
let text = "hello world";
let mut to_encrypt = String::from(text).as_bytes().to_vec();
let key = [0; 32];
let sealing_key = aead::SealingKey::new(&aead::AES_256_GCM, &key).expect("Failed get key");
let nonce: [u8; 12] = thread_rng... | true |
7cafa0897264765a7f349b611ee247b17be422ad | Rust | savish/BHTree | /src/lib.rs | UTF-8 | 20,488 | 3.8125 | 4 | [] | no_license | //! # Barnes-Hut Algorithm
//!
//! A Rust implementation of the Barnes-Hut tree in 3 dimensions.
//!
//! This implementation focuses on the use of Rusts's enumerations to describe
//! multiple coordniate systems, as well as the tree structure that forms the heart
//! of the algorithm.
//!
//! # Description
//!
//! A de... | true |
715baa264e466a235264656d8db81e413e29e9d5 | Rust | flyingfishfuse/captive_portal_rust | /commandline_option_parser.rs | UTF-8 | 4,672 | 3.203125 | 3 | [] | no_license | fn parse_commandline_arguments(){
let commandline_args = App::new("Captive Portal: Hackerman Edition")
.version("0.1.0")
.author("moop")
.about("Captive portal for both security and personal use; FREE to USE unless you are a business! Then it's 'Fuck you, Pay me'")
// CHECK if the ip address is an ip ad... | true |
c22f9d1d01ed6a80ea69fb052b167847105c3910 | Rust | kvalv/bevy-2048 | /src/main.rs | UTF-8 | 8,503 | 2.765625 | 3 | [] | no_license | #![feature(destructuring_assignment)]
use bevy::core::FixedTimestep;
use bevy::prelude::*;
use itertools::Itertools;
use std::collections::hash_set::HashSet;
use std::collections::LinkedList;
const WIDTH: u32 = 4;
const HEIGHT: u32 = 4;
#[derive(Default, Debug)]
struct Block {
value: u32,
merged: bool,
}
#[de... | true |
c27b49ba8671b86c87bd034ae655ef608bce1fcd | Rust | felixwatts/harvest | /src/variety.rs | UTF-8 | 7,500 | 2.890625 | 3 | [] | no_license | use crate::bed::Bed;
use json::JsonValue;
use crate::common::*;
use crate::constant::{ SEASON_LENGTH, WeekRange, HarvestableUnits };
use std::collections::HashMap;
use std::error::Error;
use simple_error::*;
use regex::Regex;
// Represents a variety of crop
// Loaded from params.json and used as part of the input para... | true |
be083981a589b8ab9ea5d861d40491f9a10ec29d | Rust | NanthR/lisp-rs | /src/reader.rs | UTF-8 | 8,564 | 3.40625 | 3 | [] | no_license | use crate::types::Types;
use std::str::Chars;
use std::{collections::HashMap, iter::Peekable};
pub struct Tokenizer<'a> {
chars: Peekable<Chars<'a>>,
tokens: Vec<String>,
cur_token: usize,
}
impl<'a> Tokenizer<'a> {
pub fn new(input: &'a str) -> Self {
Tokenizer {
chars: input.char... | true |
fe7240e5d68b06311ada99743dd43c0d963c8ae6 | Rust | szkkentaro/rust-hands-on | /deref_coercions/src/main.rs | UTF-8 | 466 | 3.96875 | 4 | [
"MIT"
] | permissive | use std::ops::Deref;
struct DerefExample<T> {
value: T,
}
impl<T> Deref for DerefExample<T> {
type Target = T;
fn deref(&self) -> &T {
&self.value
}
}
struct Foo;
impl Foo {
fn foo(&self) {
println!("foo");
}
}
fn main() {
let x = DerefExample { value: 'a' };
assert_eq... | true |
cb5d258612dafbbbc32cffe89d4f922f494037dd | Rust | LiquidityC/aoc | /2020/day_02/src/main.rs | UTF-8 | 1,471 | 3.34375 | 3 | [] | no_license | use std::{error::Error, str::FromStr};
use text_io::scan;
struct PasswordRule {
character: char,
password: String,
min: u32,
max: u32,
}
impl PasswordRule {
fn is_valid(&self) -> bool {
let count = self.password.chars().filter(|c| *c == self.character).count() as u32;
return count... | true |
453f62641108e663d218ba67d4c0d089e363d294 | Rust | jur0/num_base | /src/error.rs | UTF-8 | 1,297 | 3.484375 | 3 | [] | no_license | use std::error;
use std::fmt;
use self::ErrorKind::*;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Error {
kind: ErrorKind,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ErrorKind {
InvalidBase(u8),
InvalidDigit(char),
InvalidDigitBase(char, u8),
NumberOverflow,
}
impl From<ErrorKin... | true |
2037bc6cdba10887a533c21e90c6e64fe9b0300c | Rust | jakemarsden/dominoes.rs | /src/tokenizer/error.rs | UTF-8 | 2,181 | 2.828125 | 3 | [
"MIT"
] | permissive | use std::error::Error;
use std::fmt::{self, Debug, Display, Formatter};
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ParseError {
AbruptClosingOfEmptyComment,
AbruptDoctypePublicIdentifier,
AbruptDoctypeSystemIdentifier,
AbsenceOfDigitsInNumericCharacterReference,
CdataInHtmlContent,
Chara... | true |
76c5df7663441ced5a5113a19c606ea950918a03 | Rust | jaredvann/timepix-spidr-data-parser | /src/bin/heatmap_generator.rs | UTF-8 | 4,098 | 2.640625 | 3 | [
"MIT"
] | permissive | /*
* ARIADNE Experiment, Department of Physics, University of Liverpool
*
* -------------------------
* Timepix Heatmap Generator
* -------------------------
*
* timepix-spidr-data-parser/src/heatmap_generator.rs
*
* Authors: Jared Vann
*/
use std::fs;
use std::io;
use std::io::Write;
use std::path::Path;
u... | true |
0a4ed9e9ac81799a9ffcd61e1c444fe2b6decf0a | Rust | Smithay/smithay | /src/utils/clock.rs | UTF-8 | 5,381 | 2.90625 | 3 | [
"MIT"
] | permissive | use std::{cmp::Ordering, marker::PhantomData, mem::MaybeUninit, time::Duration};
/// Marker for clock source that never returns a negative [`Time`]
pub trait NonNegativeClockSource: ClockSource {}
/// Monotonic clock
#[derive(Debug)]
pub struct Monotonic;
impl ClockSource for Monotonic {
fn id() -> libc::clockid... | true |
bcb018e2eb438a2e66592c06cd845864133df513 | Rust | rgreenblatt/yew_router | /crates/yew_router_route_parser/src/parser/error.rs | UTF-8 | 18,835 | 2.78125 | 3 | [
"MIT"
] | permissive | //! Error handling.
use crate::parser::core::valid_exact_match_characters;
use crate::parser::util::skip_until;
use core::fmt::Write;
use nom::branch::alt;
use nom::character::complete::char;
use nom::error::VerboseError;
use nom::multi::many0_count;
use nom::sequence::terminated;
use std::fmt::{Debug, Display, Error a... | true |
18c32334c27245c7112cdc56c668c73651b1d672 | Rust | koivunej/aoc | /2019/day06/src/main.rs | UTF-8 | 5,377 | 3.421875 | 3 | [] | no_license | use std::collections::HashMap;
use std::io::BufRead;
use std::marker::PhantomData;
use petgraph::graph::{DiGraph, DefaultIx, NodeIndex};
use petgraph::algo::transitive_closure;
fn main() {
let stdin = std::io::stdin();
let mut locked = stdin.lock();
// almost lost my mind juggling the &str here so I ended... | true |
ce5192786dde9aa1b165eaf3339066ee04026b08 | Rust | antifuchs/fibonacci_codec | /tests/prop.rs | UTF-8 | 1,734 | 2.65625 | 3 | [
"MIT"
] | permissive | use proptest;
use fibonacci_codec::{fib_decode_u16, fib_decode_u32, fib_decode_u64, fib_decode_u8};
use fibonacci_codec::{Encode, EncodeOne};
use proptest::prelude::*;
proptest! {
#[test]
fn roundtrips(input in any::<u64>().prop_filter("Values must be >0".to_owned(),
... | true |
4ca54ac03750b294f20ddd78eee70c8893b1b99c | Rust | darfink/tap-rs | /src/nom.rs | UTF-8 | 2,608 | 3.40625 | 3 | [] | no_license | //! Tap operations for nom's `IResult`, requires the feature `nom3`.
extern crate nom;
use self::nom::Err;
use self::nom::IResult;
use self::nom::Needed;
/// Tap operations for nom's `IResult`, requires the feature `nom3`.
pub trait TapNomOps<I, O, E> {
/// Executes a closure if the value is `IResult::Done`.
... | true |
ce5f396b92706b34cb03d44f05a8eccf22088ca2 | Rust | rust-lang-ja/rust-by-example-ja | /src-old/hello/print/print_display/display.rs | UTF-8 | 1,700 | 3.859375 | 4 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::fmt; // Import `fmt`
// 2つの数字を扱うための構造体です。出力を`Display`と比較するため`Debug`
// をDeriveしています
#[derive(Debug)]
struct MinMax(i64, i64);
// `MinMax`用の`Display`を実装しています。
impl fmt::Display for MinMax {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Use `self.number` to refer to each positional data... | true |
e1eaed8e839e46e29b7ee42d7d04caf219051f8a | Rust | driveyard/driveyard | /quickdry/src/lib.rs | UTF-8 | 5,708 | 3.375 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! # Quickdry
//!
//! Quickdry is a library for arena allocation.
//!
//! An arena keeps a single pointer into a large slab of memory. Allocation is very quick, because
//! it simply bumps the pointer forward, and maintains no metadata about individual allocations. In
//! exchange, all the memory in an arena must be f... | true |
0029fd58d75474dc9eb7fab85a2e0213f12b00d3 | Rust | gaertn/rust-lp | /src/data/linear_algebra/vector/sparse.rs | UTF-8 | 12,704 | 3.234375 | 3 | [
"MIT"
] | permissive | //! # Sparse vector
//!
//! Wrapping a `Vec<(usize, _)>`, fixed size.
use std::{fmt, mem};
use std::borrow::Borrow;
use std::cmp::Ordering;
use std::collections::HashSet;
use std::fmt::{Debug, Display};
use std::iter::Sum;
use std::marker::PhantomData;
use std::ops::{Add, AddAssign, DivAssign, Mul, MulAssign, Neg};
use... | true |
21caf629a6d5d8c010809a28bc1e9b8d4283188e | Rust | reitermarkus/esp-idf-sys | /src/error.rs | UTF-8 | 1,918 | 2.734375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | #![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use core::{fmt, slice, str};
use crate::*;
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct EspError(esp_err_t);
impl EspError {
pub fn from(error: esp_err_t) -> Option<Self> {
if error == 0 {
... | true |
7ba3e323a980109ded949ad83bad11e848d3d4e3 | Rust | KaiserY/trpl-zh-cn | /listings/ch09-error-handling/listing-09-05/src/main.rs | UTF-8 | 555 | 3.171875 | 3 | [
"MIT"
] | permissive | use std::fs::File;
use std::io::ErrorKind;
fn main() {
let greeting_file_result = File::open("hello.txt");
let greeting_file = match greeting_file_result {
Ok(file) => file,
Err(error) => match error.kind() {
ErrorKind::NotFound => match File::create("hello.txt") {
... | true |
f962f04743542b0d2c74de951da6aa3d6799352e | Rust | goweiwen/bevy_mod_debug_console | /src/reflect.rs | UTF-8 | 706 | 2.625 | 3 | [] | no_license | use bevy::reflect::TypeRegistry;
use clap::{App, ArgMatches};
pub fn build_commands<'a>(app: App<'a>) -> App<'a> {
let app = app.subcommand(App::new("reflect").about("get reflection info"));
app
}
pub fn match_commands(matches: &ArgMatches, reflect: &TypeRegistry) -> String {
match matches.subcommand() {... | true |
afae4caae0279844b0614834621afcdd6f2ff715 | Rust | MrHuxu/leetcode150 | /rust/src/question_69.rs | UTF-8 | 754 | 3.734375 | 4 | [] | no_license | struct Solution;
impl Solution {
pub fn my_sqrt(x: i32) -> i32 {
let x = x as i64;
let mut left = 0;
let mut right = x;
while left <= right {
let mid = (left + right) / 2;
if mid * mid == x || (mid * mid < x && (mid + 1) * (mid + 1) > x) {
r... | true |
c1a9ee8a2fac5dff7974966032f8636d57c13253 | Rust | PolySync/nvsdk_getter | /src/actions.rs | UTF-8 | 12,877 | 2.59375 | 3 | [] | no_license | use std::collections::HashSet;
use std::convert::TryInto;
use std::io::BufRead;
use std::os::unix::fs;
use std::path::Path;
use log::{debug, error, info, warn};
use structopt::StructOpt;
use crate::cache;
use crate::error::{Error, Result};
use crate::sdkm_l3::L3Repo;
#[derive(Debug, StructOpt)]
pub enum Action {
... | true |
4d750faa2b204d7cbeb7bd168c464fcd889b1032 | Rust | bernardoamc/labs | /rust/aoc_2021/day_09/src/main.rs | UTF-8 | 1,612 | 2.90625 | 3 | [] | no_license | use pathfinding::prelude::{bfs_reach, Matrix};
#[macro_use]
extern crate lazy_static;
lazy_static! {
static ref FILE_CONTENTS: String = std::fs::read_to_string("data/example.txt").unwrap();
}
fn find_low_points(matrix: &Matrix<u32>) -> Vec<(usize, usize)> {
let mut low_points = Vec::new();
for row in 0.... | true |
74e291100555f862bfb65ad2d38a94c77eaa74ba | Rust | NailLegProcessorDivide/wallace | /src/main.rs | UTF-8 | 267 | 2.703125 | 3 | [] | no_license | mod numeric_utils;
use numeric_utils::Denotation;
fn main() {
let mut a = Denotation::new_i128(6);
let b = Denotation::new_str("1.2");
let c = a + b;
a += c;
println!("Hello, world! a: {}, b: {}, c: {}", a.get_f64(), b.get_i64(), c.get_i64());
}
| true |
cbc23d7256a455104e2b2b7789f653670defbeba | Rust | NobodyXu/async-linux-spec-fd | /src/signal_mask.rs | UTF-8 | 2,737 | 2.953125 | 3 | [
"MIT"
] | permissive | use std::io::{Result, Error};
use libc::{
sigset_t, SIG_BLOCK,
sigemptyset, sigfillset, sigaddset, sigdelset, sigismember, sigprocmask
};
use crate::Signal;
#[derive(Copy, Clone)]
pub struct SignalMask {
mask: sigset_t
}
impl Default for SignalMask {
fn default() -> Self {
Self::new()
}
}
... | true |
2c9815f824b22246aaa67319b71b1f1d9fda43c2 | Rust | PSeitz/lcov | /lcov/src/report/mod.rs | UTF-8 | 6,368 | 3.390625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | //! A coverage report.
//!
//! The [`Report`] structure contains coverage information of every file.
//!
//! [`Report`]: struct.Report.html
pub use self::error::{MergeError, ParseError};
use self::parser::Parser;
use self::section::Sections;
use super::reader::Error as ReadError;
use super::{Reader, Record, RecordKind}... | true |
f602050f2111b28b928561fd6b1cb2927286da93 | Rust | qeeg/mainspring | /examples/basic.rs | UTF-8 | 1,598 | 2.875 | 3 | [
"Apache-2.0"
] | permissive | extern crate mainspring;
use mainspring::address_map::memory::{Memory, ReadOnly, ReadWrite};
use mainspring::cpu::mos6502::MOS6502;
#[allow(unused)]
use mainspring::prelude::v1::*;
fn main() {
// A ReadOnly memory segment containing a small rom consisting of a
// LDA/STA loop. This will run until stopped. Thi... | true |
d97f739a5569b31f55f0cfa9ada225496d7e764e | Rust | pgold/gget | /src/main.rs | UTF-8 | 3,284 | 2.828125 | 3 | [] | no_license | use std::io::{Read, Write};
use std::net::TcpStream;
use std::sync::Arc;
use anyhow::{anyhow, Context, Result};
use structopt::StructOpt;
use url::Url;
mod gemini;
mod verifier;
const DEFAULT_PORT: u16 = 1965;
#[derive(StructOpt)]
struct Cli {
/// The URL to be fetched.
url: String,
#[structopt(long, ... | true |
063c0d6cee94f3113a36cd2c4b9e4d2407e3a2d7 | Rust | xfbs/aoc2020 | /12-rain-risk/src/main.rs | UTF-8 | 2,811 | 3.828125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use std::io::{self, BufRead};
use std::str::FromStr;
#[derive(Copy, Clone, Debug)]
enum Action {
North,
South,
East,
West,
Left,
Right,
Forward,
}
#[derive(Copy, Clone, Debug)]
struct Instruction {
action: Action,
value: usize
}
impl FromStr for Instruction {
type Err = String... | true |
38a2f191a3445a83ca6d4bd5a918756af1ec6893 | Rust | jtr109/leetcode-in-rust | /maximum_area_of_a_piece_of_cake_after_horizontal_and_vertical_cuts/src/lib.rs | UTF-8 | 1,731 | 3.40625 | 3 | [
"MIT"
] | permissive | pub struct Solution {}
impl Solution {
pub fn max_area(
h: i32,
w: i32,
mut horizontal_cuts: Vec<i32>,
mut vertical_cuts: Vec<i32>,
) -> i32 {
horizontal_cuts.sort();
vertical_cuts.sort();
let horizontal_lines = vec![vec![0], horizontal_cuts, vec![h]].con... | true |
077d4db654bfb85316595628ad1ab2b125b703d2 | Rust | tex-other/tex-rs | /src/section_0133.rs | UTF-8 | 1,225 | 3.140625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! @* \[10] Data structures for boxes and their friends.
//! From the computer's standpoint, \TeX's chief mission is to create
//! horizontal and vertical lists. We shall now investigate how the elements
//! of these lists are represented internally as nodes in the dynamic memory.
//!
//! A horizontal or vertical list... | true |
a8d6e5ce90ec056eeca2a4f7afdc7d58d6e30340 | Rust | stiiifff/substrate-poe-tutorial | /runtime/src/poe.rs | UTF-8 | 8,278 | 2.890625 | 3 | [
"Unlicense"
] | permissive | /// A runtime module for a simple Proof-of-existence mechanism.
use support::{decl_module, decl_storage, decl_event, ensure, StorageMap, dispatch::Result};
use support::traits::{Currency, ReservableCurrency};
use rstd::vec::Vec;
use system::ensure_signed;
pub const ERR_DIGEST_TOO_LONG: &str = "Digest too long (max 10... | true |
6ab5f1c9a445189ed5fabb9ad0bf9ee32502afaa | Rust | PrismaPhonic/HackerRank | /arrays/minimum-absolute-difference/rs-solution/minimum-absolute-difference/src/lib.rs | UTF-8 | 677 | 3.234375 | 3 | [] | no_license | fn minimum_absolute_difference(arr: &mut Vec<i32>) -> i32 {
arr.sort_unstable();
let mut min = (&arr[0] - &arr[1]).abs();
for i in 1..arr.len()-1 {
let diff = (&arr[i] - &arr[i+1]).abs();
if diff < min { min = diff };
}
min
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
... | true |
893ffb5697942ff85de56fa8f759289cd8d6b02f | Rust | dabch/rpi-led-clock | /src/main.rs | UTF-8 | 2,741 | 2.546875 | 3 | [] | no_license | extern crate image;
extern crate chrono;
mod api_query;
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
//use image::{GenericImage, ImageBuffer, RgbImage, DynamicImage};
use rust_rpi_led_matrix as m;
use std::thread;
use chrono::{DateTime, Utc};
use chrono::naive::NaiveDate;
use std::path::Path;... | true |
a31c7c69551387779008b6766e0c0367604ddbb8 | Rust | likr/atcoder | /abc009/src/bin/d.rs | UTF-8 | 1,398 | 2.546875 | 3 | [] | no_license | use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;
#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;
fn... | true |
ea3b0247f1b84bcbfdbe65b48178727bcf67a7fd | Rust | NatTuck/ntuck-neu | /content/2020-09/cs3650/notes/00-Spring/25-concurrency/rustsum/src/main.rs | UTF-8 | 731 | 2.96875 | 3 | [] | no_license |
use std::thread;
use std::sync::Arc;
fn main() {
let top = 100 * 1000 * 1000;
let xs : Arc<Vec<i64>> = Arc::new((0..top).collect());
let each = top / 10;
let mut kids = vec![];
for ii in 0..10 {
let local_xs = xs.clone();
let local_each = each.clone();
kids.push(thread::s... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.