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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
3482dd2019ec86fe621630f41fd1108ef6a81d57 | Rust | daemondragon/Trie | /src/lib.rs | UTF-8 | 3,989 | 3.265625 | 3 | [] | no_license | pub mod art;
pub mod dictionary;
pub mod distance;
pub mod limit;
mod memory;
use core::cmp::Ordering;
use core::num::NonZeroU32;
use distance::IncrementalDistance;
/// For the subject, each word's data is it's frequency.
/// Note that the frequency of the word is not representative
/// of the search done for the g... | true |
1991a1d468c7d1dce21502bcc1fecd324fdf68cd | Rust | Srynetix/adventofcode2019 | /common/src/interpreter/opcode.rs | UTF-8 | 8,004 | 3.640625 | 4 | [
"MIT"
] | permissive | //! OpCode module
use super::parameter_mode::ParameterMode;
/// Register
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct Register {
/// Value
pub value: i64,
/// Mode
pub mode: ParameterMode,
}
impl Register {
/// New register
pub fn new(value: i64, mode: ParameterMode) -> Self {
... | true |
2e989174225427b823a06775f298af7ad9e3b43d | Rust | infinityb/rust-irc | /src/legacy/watchers/register.rs | UTF-8 | 1,541 | 2.890625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use super::super::{IrcMsg, numerics};
use super::super::message_types::server;
pub type RegisterResult = Result<(), RegisterError>;
#[derive(Clone, Debug)]
pub struct RegisterError {
pub errtype: RegisterErrorType,
pub message: IrcMsg,
}
impl RegisterError {
pub fn should_pick_new_nickname(&self) -> bool... | true |
11655370ed470e4bd190d62578e59171eebfeb2d | Rust | ffizer/ffizer | /src/cfg/import_cfg.rs | UTF-8 | 795 | 2.625 | 3 | [
"CC0-1.0"
] | permissive | use super::transform_values::TransformsValues;
use crate::Result;
use schemars::JsonSchema;
#[derive(Deserialize, Serialize, Debug, Default, Clone, PartialEq, JsonSchema)]
/// define a template layer to import
pub(crate) struct ImportCfg {
pub uri: String,
pub rev: Option<String>,
pub subfolder: Option<Str... | true |
da8348f65dc12d8693f834a8e97da6da57db6452 | Rust | Carterj3/infinity-table | /src/lib.rs | UTF-8 | 695 | 3.3125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | pub mod modes;
#[derive(Debug, Clone)]
pub struct Led {
brightness: u8,
red: u8,
green: u8,
blue: u8,
}
impl Led {
pub fn new(brightness: u8, red: u8, green: u8, blue: u8) -> Led {
Led {
brightness,
red,
green,
blue,
}
}
pub ... | true |
bdb22ee7b3c179a5ad2bd090d22ec01a3cca9d91 | Rust | yssource/rxRust | /src/ops/debounce.rs | UTF-8 | 4,332 | 2.765625 | 3 | [
"MIT"
] | permissive | use crate::prelude::*;
use crate::scheduler::Instant;
use crate::{impl_helper::*, impl_local_shared_both};
use std::time::Duration;
#[derive(Clone)]
pub struct DebounceOp<S, SD> {
pub(crate) source: S,
pub(crate) scheduler: SD,
pub(crate) duration: Duration,
}
impl<S: Observable, SD> Observable for DebounceOp<S,... | true |
3d37d52461455a6ee17b790e0fdd46ad4d2c73ec | Rust | cedric-h/hecs | /src/borrow.rs | UTF-8 | 5,248 | 2.84375 | 3 | [
"Apache-2.0"
] | permissive | // Copyright 2019 Google LLC
//
// 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
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in ... | true |
9d38bc692a0a0a67ddbba06c10f6293fd60f18c6 | Rust | limpidchart/lc-renderer | /src/bar.rs | UTF-8 | 3,105 | 3.15625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use crate::error::RendererError;
use crate::proto::render::chart_view::ChartViewBarLabelPosition;
use crate::proto::render::ChartView;
use lc_render::BarLabelPosition;
// Get bar label position from protobuf.
pub(crate) fn get_bar_label_position(view: &ChartView) -> Result<BarLabelPosition, RendererError> {
match ... | true |
f3e06bb96075ed08248874e70b86239e64dbcadd | Rust | riazahmed2246/code-generator | /src/generator.rs | UTF-8 | 2,656 | 3.6875 | 4 | [] | no_license | use rand::distributions::Distribution;
use rand::{seq::SliceRandom, thread_rng, Rng};
struct Hexadecimal;
impl Distribution<char> for Hexadecimal {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> char {
*b"0123456789abcdef".choose(rng).unwrap() as char
}
}
struct Decimal;
impl Distribution<char> f... | true |
9cd42144d789a1c316de8615dceb7f07e698542f | Rust | frankschmitt/advent_of_code | /2021/src/a21_dirac_dice.rs | UTF-8 | 6,731 | 3.46875 | 3 | [
"MIT"
] | permissive | use std::cmp::{ min, max };
use itertools::Itertools;
use std::collections::HashMap;
fn parse_pos(line: &str) -> u32 {
let (_, pos_str) = line.split_once(": ").unwrap();
return pos_str.parse::<u32>().unwrap();
}
// move n steps, and wrap around to position 1 after 10
fn compute_new_pos(old_pos: u32, n: u32) -... | true |
321c45c28993659fc06458f41e4fd70d336cba3b | Rust | Jbat1Jumper/Twins | /src/entities/intro/mega_ray.rs | UTF-8 | 2,599 | 2.78125 | 3 | [] | no_license | use ggez::graphics;
use ggez::graphics::Color;
use ggez::graphics::{DrawMode, Point2};
use ggez::Context;
use entities::{Entity, EntityData};
use messages::{Message, MessageSender};
use palette::Palette;
use math::VectorUtils;
const PRECISION: f32 = 0.5;
pub struct MegaRay {
entity_data: EntityData,
cycle: ... | true |
97dbe347cfdfab17d813888ae7422889810797cf | Rust | ankitects/fluent-rs | /intl-memoizer/examples/pluralrules.rs | UTF-8 | 1,052 | 2.8125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use intl_memoizer::{IntlMemoizer, Memoizable};
use intl_pluralrules::{PluralCategory, PluralRuleType, PluralRules as IntlPluralRules};
use unic_langid::LanguageIdentifier;
struct PluralRules(pub IntlPluralRules);
impl PluralRules {
pub fn new(lang: LanguageIdentifier, pr_type: PluralRuleType) -> Result<Self, &'st... | true |
7ff07c78964d134987698a1f0851ebe8342de3ba | Rust | Max-astro/CLRS-3rd-rs | /graph/src/directed_graph.rs | UTF-8 | 20,168 | 2.71875 | 3 | [] | no_license | // #![feature(total_cmp)]
use std::cell::RefCell;
use std::collections::{BinaryHeap, VecDeque};
use std::rc::Rc;
#[derive(Eq, PartialEq, Debug)]
enum Color {
White,
Gray,
Black,
}
type Vptr = Rc<RefCell<Vertex>>;
type Vlist = Vec<Rc<RefCell<Vertex>>>;
pub struct Vertex {
idx: usize,
... | true |
4d1d84eeb7dee0324b9e7b8f7172a2f2d6df6411 | Rust | ShuyoTrader/huobi_future_async | /src/client/account.rs | UTF-8 | 15,530 | 2.71875 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"MIT",
"Apache-2.0"
] | permissive | use super::HuobiFuture;
use crate::{
models::*,
};
use failure::Fallible;
use futures::prelude::*;
use std::{collections::BTreeMap};
impl HuobiFuture {
// Account Information
pub fn get_account_info<S1>(
&self,
symbol: S1,
) -> Fallible<impl Future<Output = Fallible<APIResponse<Vec<Acc... | true |
bc37b37c1626b3865328fa6e3dff47f97d40f8fe | Rust | HelveticaScenario/micro-lisp | /micro-lisp-vm/src/types.rs | UTF-8 | 2,595 | 3.125 | 3 | [] | no_license | use crate::VM;
use rand::Rng;
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt;
use std::rc::Rc;
pub struct Env {
pub parent: Option<Rc<Box<Env>>>,
pub definitions: RefCell<HashMap<String, Val>>,
}
impl Env {
pub fn new(parent: Option<Rc<Box<Env>>>) -> Self {
Env {
parent,
def... | true |
4a75ad05e0e0612b633e4a80c37a888a1739b8aa | Rust | aumykun/db | /src/db.rs | UTF-8 | 13,754 | 2.546875 | 3 | [] | no_license | use std::collections::BTreeMap;
use std::mem::discriminant;
use std::sync::Mutex;
use rand::Rng;
use serde_derive::{Serialize, Deserialize};
use sled::Tree;
use problem::{Problem, ToProblem};
use crate::getset::{EasyGet, GetSet};
//use getset::{EasyGet, GetSet};
use self::DBError::*;
#[allow(dead_code)]
#[derive(De... | true |
5f0d9a6a158ed7e360daeb0a37d4464166385c72 | Rust | yanshiyason/cob-rust | /src/main.rs | UTF-8 | 1,512 | 2.671875 | 3 | [] | no_license | use std::env;
use std::fs;
use std::path::Path;
use toml;
mod async_types;
mod config;
mod git;
mod github;
mod remote_cob;
mod remote_fire_cob;
use config::Config;
use remote_cob::remote_cob;
use remote_fire_cob::remote_fire_cob;
static DEFAULT_CONFIG: &str = r#"prefix = ""
[github]
username = ""
password = ""
aut... | true |
74a0f1aec0cada765b832ebfb1d82bc7dea33277 | Rust | ghuntley/monorepo | /fun/defer_rs/examples/undefer.rs | UTF-8 | 819 | 3.828125 | 4 | [
"MIT"
] | permissive | // Go's defer in Rust, with a little twist!
struct Defer<F: Fn()> {
f: F
}
impl <F: Fn()> Drop for Defer<F> {
fn drop(&mut self) {
(self.f)()
}
}
// Only added this for Go-syntax familiarity ;-)
fn defer<F: Fn()>(f: F) -> Defer<F> {
Defer { f }
}
// Changed your mind about the defer?
// (Not... | true |
3c3d887499ae2d4479bcf4284e8620fec51a1674 | Rust | losfair/naptd | /src/checksum.rs | UTF-8 | 3,908 | 2.8125 | 3 | [] | no_license | // Ported from https://android.googlesource.com/platform/system/core/+/master/libnetutils/checksum.c.
use byteorder::{ByteOrder, LittleEndian, BigEndian};
use std::net::{Ipv4Addr, Ipv6Addr};
/* function: ip_checksum_add
* adds data to a checksum. only known to work on little-endian hosts
* current - the current che... | true |
0b5fce0953271f292ec7a71f4eadc3b1429dfc32 | Rust | nakat-t/nlp100 | /q10/src/main.rs | UTF-8 | 375 | 2.90625 | 3 | [
"MIT"
] | permissive | use std::io;
fn main() {
let mut line_count = 0;
loop {
let mut line = String::new();
match io::stdin().read_line(&mut line) {
Ok(0) => break,
Ok(_) => line_count += 1,
Err(err) => {
println!("error: {}", err);
break;
... | true |
b54e2cce659581ac55ef881e513f1a40a86912da | Rust | ecafkoob/ockam | /implementations/rust/ockam/ockam_vault_core/src/secret.rs | UTF-8 | 657 | 3.21875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use serde::{Deserialize, Serialize};
use zeroize::Zeroize;
/// Handle to a cryptographic Secret
/// Individual Vault implementations should map secret handles
/// into implementation-specific Secret representations (e.g. binaries, or HSM references)
/// stored inside Vault (e.g. using HashMap)
#[derive(Serialize, Dese... | true |
8cdc7670a46eaf780e3a28dc9d7d2e1026d0539d | Rust | Emilgardis/debug_stub_derive | /src/lib.rs | UTF-8 | 12,852 | 2.828125 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | // Copyright (c) 2017 Ivo Wetzel
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to... | true |
654cc9ec59b564504b22bd91aea21e3ba0326faa | Rust | AirGuanZ/rust_painter | /03_ol_renderer/src/math/color.rs | UTF-8 | 2,465 | 3.3125 | 3 | [] | no_license | //! Color traits and impl for vectors
extern crate cgmath;
use self::cgmath::*;
use math::Real;
pub type Color3f = Vector3<Real>;
pub type Color4f = Vector4<Real>;
pub fn max_elememt_wise_color3(a: Color3f, b: Color3f) -> Color3f {
color3(a.x.max(b.x), a.y.max(b.y), a.z.max(b.z))
}
pub trait ColorTrait3<T> {
... | true |
b3df3f87a9f8d23754d2a005b01499111079975f | Rust | hessifer/Rust | /vector_of_vector_example/src/main.rs | UTF-8 | 2,246 | 3.28125 | 3 | [] | no_license | fn main() {
let ctx_lines = 2;
let needle = "oo";
let haystack = "\
Every face, every shop, bedroom window, public-house,
and dark square is a picture feverishly turned--in search
of what? It is the same with books. What do you seek
through millions of pages?";
// hold line numbers wher... | true |
1fd09c0ad1191e7ae3882de790a15e7ca3376517 | Rust | pyncc/adventofcode2019 | /day_1/src/main.rs | UTF-8 | 988 | 3.171875 | 3 | [] | no_license | use std::io::{self, BufRead};
use std::cmp::Ordering;
fn fuel_required_fuel(fuel_mass: i32) -> i32 {
let fuel_fuel_mass: i32 = (fuel_mass as f32 / 3_f32).floor() as i32 - 2;
// println!("fuel {}, extra {}", fuel_mass, fuel_fuel_mass);
return fuel_fuel_mass + match fuel_fuel_mass.cmp(&0) {
Ordering... | true |
5c15c5785ce5750764f14fbcfea7a33f8446e847 | Rust | bevyengine/bevy | /crates/bevy_sprite/src/texture_atlas.rs | UTF-8 | 5,374 | 3.15625 | 3 | [
"Apache-2.0",
"MIT",
"Zlib",
"LicenseRef-scancode-free-unknown",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-other-permissive"
] | permissive | use crate::Anchor;
use bevy_asset::Handle;
use bevy_ecs::{component::Component, reflect::ReflectComponent};
use bevy_math::{Rect, Vec2};
use bevy_reflect::{Reflect, TypeUuid};
use bevy_render::{color::Color, texture::Image};
use bevy_utils::HashMap;
/// An atlas containing multiple textures (like a spritesheet or a ti... | true |
1f6910803c9b5e5deca875eac4c7057a9da87a1f | Rust | drupalio/midi_game | /src/resources.rs | UTF-8 | 2,773 | 2.578125 | 3 | [] | no_license | use crate::input::*;
use macroquad::audio::*;
use macroquad::prelude::*;
use macroquad_tantan_toolbox::resources::*;
#[derive(Eq, PartialEq, Hash, Clone, Copy)]
pub enum TransitionData {
Slide,
}
impl Default for TransitionData {
fn default() -> Self {
TransitionData::Slide
}
}
pub struct SharedD... | true |
934c179e85cbb0b3cbfe15fa158835c363dd2ce8 | Rust | tomaka/simple-mad.rs | /simplemad/src/lib.rs | UTF-8 | 20,743 | 3.234375 | 3 | [
"MIT"
] | permissive | /*!
This crate provides an interface to libmad, the MPEG audio decoding library.
To begin, create a new `Decoder` from a byte-oriented source using
`Decoder::decode` or `Decoder::decode_interval`. Fetch results using
`get_frame` or the `Iterator` interface.
`Frame` and `MadError` correspond to libmad's struct types `... | true |
d000df16355884496ab7d9061bc44749cebc5d4b | Rust | opp11/calcr | /src/input/default.rs | UTF-8 | 1,100 | 2.84375 | 3 | [
"MIT"
] | permissive | use std::io;
use std::io::Write;
use super::CMD_PROMPT;
use super::{InputHandler, InputCmd};
use super::Key;
pub struct DefaultInputHandler;
impl DefaultInputHandler {
pub fn new() -> DefaultInputHandler {
DefaultInputHandler
}
}
impl InputHandler for DefaultInputHandler {
fn start(&mut self) -> ... | true |
0ab022b84f48394b223e1362229595cef8d9f98e | Rust | marcosfede/rust-python-interop | /pyo3_strd/src/lib.rs | UTF-8 | 417 | 2.53125 | 3 | [] | no_license | use pyo3::prelude::*;
use pyo3::wrap_pyfunction;
use levenshtein::levenshtein;
#[pyfunction]
/// Formats the sum of two numbers as string
fn edit_distance(x: &str, y: &str) -> PyResult<usize> {
Ok(levenshtein(x, y))
}
/// This module is a python module implemented in Rust.
#[pymodule]
fn pyo3_strd(_py: Python, m... | true |
f1e2f4b5d468e67046b8c9e86ec0c0be4231241c | Rust | petergarnaes/rocket_jsonapi | /test_suite/tests/test_rocket_response.rs | UTF-8 | 24,668 | 2.75 | 3 | [] | no_license | #![allow(dead_code)]
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use]
extern crate rocket;
use rocket_jsonapi::{Linkify, ResourceIdentifiable, ResourceType};
use serde::Serialize;
#[derive(Serialize, ResourceType, ResourceIdentifiable, Linkify)]
struct Test {
id: i32,
message: String,
}
mod test_out... | true |
8499732559e60d3b4c54d10e57d8a803ca1438f0 | Rust | bitc/adl | /haskell/compiler/tests/test5/rs-output/test5/adl/test5.rs | UTF-8 | 2,423 | 2.578125 | 3 | [] | no_license | // @generated from adl module test5
use serde::Deserialize;
use serde::Serialize;
#[derive(Clone,Deserialize,Eq,Hash,PartialEq,Serialize)]
pub enum U1 {
#[serde(rename="v")]
V,
}
#[derive(Clone,Deserialize,Eq,Hash,PartialEq,Serialize)]
pub enum U2 {
#[serde(rename="v")]
V(i16),
}
#[derive(Clone,Deserialize,... | true |
1018a48cc73d3913931197c86f2f40bc22ca1fd3 | Rust | ys-kalyakin/leetcode | /rust/src/add_two_numbers/mod.rs | UTF-8 | 2,275 | 3.84375 | 4 | [
"MIT"
] | permissive | /// https://leetcode.com/problems/add-two-numbers/
pub struct ListNode {
pub val: i32,
pub next: Option<Box<ListNode>>,
}
impl ListNode {
#[inline]
fn new(val: i32) -> Self {
ListNode { next: None, val }
}
#[allow(dead_code)]
fn new_node(val: i32, next: ListNode) -> Self {
... | true |
bfc06eeccd6eef7c305d2bb386d6f6c9415b8a3e | Rust | kahgeh/learn-rust | /my-redis/examples/importance-of-send-trait.rs | UTF-8 | 1,201 | 3.546875 | 4 | [] | no_license | use std::rc::Rc;
use tokio::task::yield_now;
#[tokio::main]
async fn main() {
tokio::spawn(async {
let val = String::from("bizzaro");
{
let rc = Rc::new("hello");
println!("{}", rc);
}
yield_now().await;
println!("{}", val);
// Given that the... | true |
0885ab32f37601b17fcc77503d9c61e98259b07c | Rust | nguyenminhhieu12041996/casper-node | /node/src/components/deploy_acceptor/config.rs | UTF-8 | 617 | 2.765625 | 3 | [
"Apache-2.0"
] | permissive | use datasize::DataSize;
use serde::{Deserialize, Serialize};
/// Configuration options for fetching.
#[derive(Copy, Clone, DataSize, Debug, Deserialize, Serialize)]
pub struct Config {
verify_accounts: bool,
}
impl Config {
/// Constructor for deploy_acceptor config.
pub fn new(verify_accounts: bool) -> S... | true |
bdf5ad8a2bd47978db4fe778cebe595833b601ea | Rust | lnicola/serde_fix | /fix50sp2/src/messages/party_action_request.rs | UTF-8 | 3,005 | 2.609375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive |
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
pub struct PartyActionRequest {
/// MsgType = DH
#[serde(flatten)]
pub standard_message_header: super::super::standard_message_header::StandardMessageHeader<'D', 'H'>,
/// PartyActionRequestID
#[serde(rename ... | true |
a29229ecded06f5303047bee6920524b1ec13e9d | Rust | raviqqe/lisp-like-gum | /farmem/src/type_id.rs | UTF-8 | 276 | 2.6875 | 3 | [
"Unlicense"
] | permissive | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
Serialize, Deserialize)]
pub struct TypeId(u64);
impl TypeId {
pub fn new(i: u64) -> Self {
TypeId(i)
}
}
impl From<TypeId> for usize {
fn from(t: TypeId) -> Self {
t.0 as usize
}
}
| true |
a6da746f62acf73ce2ec58ca0294a5c05022fef1 | Rust | neosam/shoppinglist_srv | /src/main.rs | UTF-8 | 6,715 | 2.5625 | 3 | [] | no_license | #![feature(plugin, custom_derive)]
#![plugin(rocket_codegen)]
extern crate rocket;
extern crate rocket_contrib;
extern crate shoppinglist;
extern crate serde_json;
extern crate uuid;
#[macro_use] extern crate serde_derive;
extern crate serde_yaml;
use rocket::State;
use rocket::response::content::Content;
use rocket:... | true |
845aefd9b154a2dbb0c80500cff85333d519d8e1 | Rust | typst/typst | /crates/typst-library/src/math/align.rs | UTF-8 | 1,717 | 3.015625 | 3 | [
"Apache-2.0",
"Bitstream-Vera",
"CC-BY-4.0",
"OFL-1.1",
"LicenseRef-scancode-gust-font-1.0",
"BSD-3-Clause",
"LicenseRef-scancode-ubuntu-font-1.0",
"0BSD",
"LicenseRef-scancode-free-unknown",
"LicenseRef-scancode-public-domain",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer"
] | permissive | use super::*;
/// A math alignment point: `&`, `&&`.
///
/// Display: Alignment Point
/// Category: math
#[element(LayoutMath)]
pub struct AlignPointElem {}
impl LayoutMath for AlignPointElem {
#[tracing::instrument(skip(ctx))]
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> {
ctx.pus... | true |
36070a59e75156633bf486ab9891e0301e9f3d7a | Rust | ifukazoo/monkey_rust | /src/env.rs | UTF-8 | 2,491 | 3.65625 | 4 | [
"MIT"
] | permissive | use crate::builtin;
use crate::object::Object;
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt;
use std::rc::Rc;
/// 環境参照
pub type RefEnv = Rc<RefCell<Environment>>;
/// 環境のマップ
#[derive(Debug, PartialEq)]
pub struct Environment {
map: HashMap<String, Object>,
outer: Option<RefEnv>,
}
impl... | true |
3f92a8ef9fb2f3558510581574b3bdd206219235 | Rust | shadaj/adventofcode-2020 | /src/day4/a.rs | UTF-8 | 1,119 | 2.59375 | 3 | [] | no_license | // BEGIN UTIL (https://codeforces.com/blog/entry/67391)
use std::{collections::HashSet, io::{stdin, stdout, BufWriter, Write}};
#[allow(unused_imports)]
use std::writeln;
fn main() {
let out = &mut BufWriter::new(stdout());
let mut seen_keys: HashSet<String> = HashSet::new();
let required_keys = [ "byr", "iyr", ... | true |
f56fb439123abe0a95572f227d405a3f3c5b1cdc | Rust | akiles/embassy | /embassy-stm32/src/flash/f7.rs | UTF-8 | 3,287 | 2.71875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use core::convert::TryInto;
use core::ptr::write_volatile;
use core::sync::atomic::{fence, Ordering};
use crate::flash::Error;
use crate::pac;
pub(crate) unsafe fn lock() {
pac::FLASH.cr().modify(|w| w.set_lock(true));
}
pub(crate) unsafe fn unlock() {
pac::FLASH.keyr().write(|w| w.set_key(0x4567_0123));
... | true |
f7347f072f91b8222531fd0dc4a875a9fe7dddca | Rust | cynecx/rust-analyzer | /crates/ide/src/syntax_highlighting/format.rs | UTF-8 | 2,863 | 2.90625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //! Syntax highlighting for format macro strings.
use syntax::{
ast::{self, FormatSpecifier, HasFormatSpecifier},
AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange,
};
use crate::{
syntax_highlighting::HighlightedRangeStack, HighlightTag, HighlightedRange, SymbolKind,
};
#[derive(Default... | true |
7fface1af2a593fdb6bc036559ff8f64a153b9e8 | Rust | gomain/rust-bouncy | /src/config.rs | UTF-8 | 1,695 | 3.4375 | 3 | [] | no_license | use std::env::Args;
#[derive(Debug)]
pub struct Config {
pub frame_width: u32,
pub frame_height: u32,
}
#[derive(Debug)]
pub enum ParseError {
TooFewArgs,
TooManyArgs,
InvalidInteger(String),
}
pub struct ParseArgs {
args: Args,
}
impl Iterator for ParseArgs {
type Item = String;
fn ... | true |
9b7107e474b2a83f31c339f55a2799b6e17a130c | Rust | brooks-builds/chooser_collector | /src/lib.rs | UTF-8 | 2,451 | 2.859375 | 3 | [] | no_license | use std::fs::File;
use std::io::Write;
use std::sync::mpsc::channel;
use std::thread::spawn;
use arguments::Arguments;
use choice::Choice;
use eyre::{bail, Result};
use interactive_mode::InteractiveMode;
use twitch_chat_wrapper::ChatMessage;
use twitch_mode::TwitchMode;
mod arguments;
mod choice;
mod interactive_mode... | true |
bda532bff40142e1454c47f5c99681b4339ab071 | Rust | litttley/rust_snippet | /stock_histery/src/main.rs | UTF-8 | 2,167 | 2.953125 | 3 | [] | no_license | extern crate hyper;
extern crate serde_json;
use hyper::Client;
use std::io::Read;
use serde_json::{ Value};
fn main() {
/* 请求地址:https://api.shenjian.io/?appid=944bb9ddadf7491420bd8dc43f10370746d9
请求参数:code=601857&index=false&k_type=day&fq_type=qfq&start_date=2016-04-10&end_date=
请求方式:GET*/
loop {
... | true |
1588565d4d10c6268014d6d9fc56f9507381f360 | Rust | Deividy/lab | /rust/guessing/src/main.rs | UTF-8 | 766 | 3.546875 | 4 | [] | no_license | use rand::Rng;
use std::cmp::Ordering;
use std::io;
fn main() {
let secret_number = rand::thread_rng().gen_range(1, 420);
loop {
println!("Can you guess the number?");
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("#fail");
l... | true |
d0da58844588f18aeba437ab9516ee1395276098 | Rust | SidOfc/2048-rust | /src/game.rs | UTF-8 | 15,774 | 3.421875 | 3 | [] | no_license | use std::ops::Add;
use super::rand::{thread_rng, Rng};
use super::direction::Direction;
/// A mask with a single section of 16 bits set to 0.
/// Used to extract a "horizontal slice" out of a 64 bit integer.
pub static ROW_MASK: u64 = 0xFFFF;
/// A `u64` mask with 4 sections each starting after the n * 16th bit.
/// ... | true |
f8c98216f076006fab21edf08ff7e45d410ea473 | Rust | jeremy-sylvis/2019-advent-code | /day_3_manhattan_distance/src/point_parser.rs | UTF-8 | 5,137 | 3.71875 | 4 | [
"MIT"
] | permissive | use nalgebra::geometry::Point2;
use std::str::FromStr;
pub fn parse_points(directions: &Vec<&str>) -> Vec<Point2<f32>> {
const DIRECTION_UP: char = 'U';
const DIRECTION_RIGHT: char = 'R';
const DIRECTION_DOWN: char = 'D';
const DIRECTION_LEFT: char = 'L';
let mut last_point: Point2<f32> = Point2::... | true |
c5227f29a1e979b5580cda7336692ee04a900523 | Rust | leudz/shipyard | /tests/remove.rs | UTF-8 | 5,002 | 2.734375 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use core::any::type_name;
use shipyard::error;
use shipyard::*;
#[derive(PartialEq, Eq, Debug)]
struct U32(u32);
impl Component for U32 {}
#[test]
fn no_pack() {
#[derive(PartialEq, Eq, Debug)]
struct USIZE(usize);
impl Component for USIZE {}
let world = World::new_with_custom_lock::<parking_lot::Raw... | true |
1b8dac3a4b3044b8c14371b84dc4dfc0e82a29c1 | Rust | abdulsemiu-atanda/StarWars | /src/main.rs | UTF-8 | 832 | 2.546875 | 3 | [] | no_license | use console::style;
use loading::Loading;
use std::collections::HashMap;
mod api;
mod handlers;
use handlers::terminal::*;
fn main() {
let mut hash = HashMap::new();
// setup hash to match to shorthand values
hash.insert("People".to_string(), "P".to_string());
hash.insert("Starships".to_string(), "S... | true |
a9e79fc8f7037c6914de8f8bbdb35ea1e66f4baf | Rust | UsairimIsani/teaching-rs | /src/bin/text.rs | UTF-8 | 692 | 2.96875 | 3 | [] | no_license | use std::{
fs::File,
io::{stdin, Read, Write},
path::PathBuf,
};
fn main() {
let mut file_name = String::new();
stdin().read_line(&mut file_name).unwrap();
let mut file = File::open(&mut file_name).expect("Couldn't Open File !");
let mut content = String::new();
file.read_to_string(... | true |
dcf56a656443880b575afd038da40f5c065a9b66 | Rust | gollum23/learning-rust | /day2/randuser/src/main.rs | UTF-8 | 761 | 4.09375 | 4 | [] | no_license | extern crate rand;
use rand::Rng;
use std::ops::Add;
pub struct Point {
x:i32,
y:i32,
}
impl Point {
fn random() -> Self{
let mut tr = rand::thread_rng();
Point {
x: tr.gen(),
y: tr.gen(),
}
}
}
// Implement add method for point struct
impl Add for Po... | true |
cb355805cb9b83a8a7a67840250f8e2c51586d01 | Rust | Freyert/sortssortssorts | /src/bubble.rs | UTF-8 | 703 | 3.578125 | 4 | [] | no_license | pub fn sort(arr: &mut Vec<i32>) {
let length = arr.len();
'outer: loop {
let mut swapped = false;
for index in 1..length {
let value = arr[index];
if arr[index - 1] > value {
arr[index] = arr[index-1];
arr[index -1] = value;
... | true |
231933d9bbd9b1de16482be56c587b42724a2adf | Rust | qeedquan/challenges | /kattis/license-to-launch.rs | UTF-8 | 1,317 | 3.375 | 3 | [
"MIT"
] | permissive | /*
Birk has made a new shiny rocket and just received his licence from the Bluesky Global Order (BGO) to launch anytime within the next n days.
He is, however, worried that the rocket will hit space junk on its way. In order minimize the risk of a collision, Birk has made a model of how many pieces of space junk there... | true |
40548f6effae32b0523a3d832178bd160e63d458 | Rust | dikuchan/openedx-admin | /backend/src/model/user.rs | UTF-8 | 2,877 | 2.78125 | 3 | [] | no_license | use crate::{
config::db::Connection,
model::{login_history::LoginHistory, user_token::UserToken},
schema::users::{self, dsl::*},
};
use diesel::prelude::*;
use uuid::Uuid;
#[derive(Identifiable, Queryable, Serialize, Deserialize)]
pub struct User {
pub id: i32,
pub email: String,
pub password: ... | true |
434e3f83876410869d3612f92fc8d8d63cbcd215 | Rust | TanNgocDo/hbbft | /src/queueing_honey_badger/mod.rs | UTF-8 | 11,619 | 3.046875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! # Queueing Honey Badger
//!
//! This works exactly like Dynamic Honey Badger, but it has a transaction queue built in. Whenever
//! an epoch is output, it will automatically select a list of pending transactions and propose it
//! for the next one. The user can continuously add more pending transactions to the queu... | true |
87d3501732a6213222be47049c4e543e89e5160e | Rust | shika-blyat/YARRT | /src/cameras/pinhole_camera.rs | UTF-8 | 2,066 | 2.921875 | 3 | [] | no_license | use crate::structs::{Ray, Vec3, unit_vector, cross};
use super::Camera;
use rand::Rng;
pub struct PinholeCamera {
pub origin: Vec3,
lower_left_corner: Vec3,
horizontal: Vec3,
vertical: Vec3,
// shutter open/close times
time0: f64,
time1: f64,
}
impl PinholeCamera {
pub fn new_look_at(... | true |
5c78b2536a4b4c0c3c4e1b2c4332a3ad961d7746 | Rust | as3richa/calico | /src/matrix.rs | UTF-8 | 21,244 | 2.984375 | 3 | [] | no_license | use crate::bvh::Ray;
use crate::tuple::{Tuple, Tuple3};
use crate::Float;
use std::ops;
#[cfg(test)]
use crate::eq_approx;
#[derive(Clone, Debug)]
pub struct Matrix([[Float; 4]; 4]);
impl Matrix {
pub fn new(xs: [[Float; 4]; 4]) -> Matrix {
Matrix(xs)
}
pub fn identity() -> Matrix {
Matr... | true |
11a36fb2adbbdbb61989d5d6faaf5d9a1abdf620 | Rust | fossabot/rust-jvm-1 | /classfile/src/attr/mod.rs | UTF-8 | 1,141 | 2.984375 | 3 | [] | no_license | pub mod info;
use error::*;
use self::info::AttrInfo;
use super::constant::ConstantPool;
#[derive(Debug)]
pub struct Attr {
name_index: usize,
pub info: AttrInfo,
}
impl Attr {
pub fn name<'a>(&self, pool: &'a ConstantPool) -> Option<&'a str> {
pool.get_str(self.name_index)
}
}
impl_read! {
... | true |
212f1d64c301947308bad6b9ebf0b77364e52583 | Rust | fits/try_samples | /rust/image/thumbnail_jpegdecoder/src/main.rs | UTF-8 | 830 | 2.65625 | 3 | [] | no_license |
use image::{ DynamicImage, ImageResult };
use image::io::Reader as ImageReader;
use image::codecs::jpeg::JpegDecoder;
use std::env;
use std::time::Instant;
fn to_u32(v: String) -> Option<u32> {
v.parse().ok()
}
fn main() -> ImageResult<()> {
let mut args = env::args().skip(1);
let file = args.next().un... | true |
f3b889de18c47a36fd87f5da8be8ef2bf15eabc0 | Rust | rust-lang/rustfmt | /tests/target/chains_with_comment.rs | UTF-8 | 3,512 | 2.765625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | // Chains with comment.
fn main() {
let x = y // comment
.z;
foo // foo
// comment after parent
.x
.y
// comment 1
.bar() // comment after bar()
// comment 2
.foobar
// comment after
// comment 3
.baz(x, y, z);
self.r... | true |
8bb158d58f47a9899f3c3380fa56ac11144f8958 | Rust | mystor/literalext | /src/internal.rs | UTF-8 | 14,422 | 3.21875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use {RawInt, IntLit, FloatLit};
use std::char;
use std::ops::{Index, RangeFrom};
use std::ascii::AsciiExt;
/// Filter the input string, removing all bytes which match the given input
/// byte in place, without allocation.
///
/// # Panics
///
/// Panics if the filter byte is not a valid ASCII character.
fn string_fil... | true |
e0ff5b27d21f24be1718cb4114c41b5d9c2147a8 | Rust | thor314/lighthouse | /eth2/utils/rest_types/src/node.rs | UTF-8 | 1,080 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | //! Collection of types for the /node HTTP
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use types::Slot;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Encode, Decode)]
/// The current syncing status of the node.
pub struct SyncingStatus {
/// The starting slot of sync.
///... | true |
ee6f7e9e80c8db496ec3ceb5f70a2671da4b1c38 | Rust | youngqqcn/LeetCodeNotes | /src/0015_three_sum/three_sum.rs | UTF-8 | 1,558 | 3.078125 | 3 | [
"MIT"
] | permissive | /*
date: 2021-05-22 20:25
author: yqq
descriptions:
*/
struct Solution{}
impl Solution {
pub fn three_sum(nums: Vec<i32>) -> Vec<Vec<i32>> {
let mut ns = nums.clone();
let mut results: Vec<Vec<i32>> = vec![];
ns.sort_by(|a, b| a.cmp(b));
for i in 0..ns.len() {
let a ... | true |
b1d349620ce0a71d502ea477090a415273469370 | Rust | VCNinc/trs.js | /src/trace.rs | UTF-8 | 5,770 | 3.15625 | 3 | [
"MIT"
] | permissive | use wasm_bindgen::prelude::*;
use crate::{
key::{PublicKey, ascii_to_public},
prelude::*,
sig::{compute_sigma, Signature, Tag}
};
/// Encodes the relationship of two signatures
#[derive(Debug, Eq, PartialEq)]
pub enum Trace<'a> {
/// `Indep` indicates that the two given signatures were cons... | true |
8510e7dfbe39ff4ac5003c9eb73fdeef69e769a3 | Rust | yutiansut/rlink-rs | /rlink-connectors/connector-kafka/src/source/checkpoint.rs | UTF-8 | 2,653 | 2.53125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use rlink::core::checkpoint::{CheckpointFunction, CheckpointHandle, FunctionSnapshotContext};
use rlink::core::runtime::TaskId;
use crate::state::{KafkaSourceStateCache, OffsetMetadata, PartitionMetadata};
#[derive(Debug, Clone)]
pub struct KafkaCheckpointFunction {
pub(crate) state_cache: Option<KafkaSourceState... | true |
014c3ae977219f3250b844aa8aa87090e2ca97e8 | Rust | vojta7/pra-lang-front-end | /pra_lang_interface/src/lib.rs | UTF-8 | 3,893 | 2.921875 | 3 | [] | no_license | use mylib::ast::{ArgList, VarVal};
use mylib::{execute, parse, Buildins, Lexer, ParsingError, Program, RuntimeError, Token};
use serde::Serialize;
use std::collections::HashMap;
use wasm_bindgen::prelude::*;
#[derive(Serialize)]
struct ExternalRuntimeError {
position: usize,
description: String,
}
#[derive(Se... | true |
f878d9a1e82464e1a99ba28179bbbe9af740b78b | Rust | jpcenteno/caesar-cipher-decryptor | /src/main.rs | UTF-8 | 2,114 | 3.71875 | 4 | [] | no_license | extern crate clap;
use clap::{App, Arg};
const KEY_RANGE: u8 = 1 + ('Z' as u8) - ('A' as u8);
fn shift_alphabetic_char(c: char, n: u8) -> char {
let offset = (c as u8) - ('A' as u8);
let shift = (offset + n) % KEY_RANGE;
('A' as u8 + shift) as char
}
fn shift_char(c: char, n: u8) -> char {
match c {
... | true |
fac8b954039f8a710259f4e66c2f8c52cf9a780e | Rust | pwil3058/proc-macro-workshop | /seq/src/lib.rs | UTF-8 | 877 | 2.671875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use proc_macro::TokenStream;
use syn;
#[proc_macro]
pub fn seq(input: TokenStream) -> TokenStream {
let seq_data = syn::parse_macro_input!(input as SeqData);
eprintln!("INNER STREAM: {:#?}", seq_data);
TokenStream::new()
}
#[derive(Debug)]
struct SeqData {
ident: syn::Ident,
range: syn::ExprRange... | true |
c4d94dcd31208b8861d9d88900b9ddcc954efd0b | Rust | bryanburgers/advent-of-code-2017.rs | /day-4/src/main.rs | UTF-8 | 1,333 | 3.59375 | 4 | [] | no_license | use std::io::{Read, self};
use std::collections::HashSet;
fn main() {
let mut buffer = String::new();
// Get the input
io::stdin().read_to_string(&mut buffer)
.expect("Read stdin");
let buffer = buffer.trim();
let lines : Vec<&str> = buffer.split('\n').collect();
let input : Vec<Vec<&... | true |
9cf84606cee9f250d51af302610c92c384da6ed3 | Rust | JeffLi01/learn_rust_by_test | /src/learn_error.rs | UTF-8 | 691 | 3.5 | 4 | [] | no_license | use std::fmt;
#[derive(Debug, Clone)]
pub struct Error {
pub message: String,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{}", self.message)
}
}
impl std::error::Error for Error {
fn description(&self) -> &str {
&self.m... | true |
134553999857d3387ec25cfc37ee5c7087b722b1 | Rust | backwardspy/nessa | /nessa-ppu/src/lib.rs | UTF-8 | 5,294 | 2.6875 | 3 | [] | no_license | #![warn(
clippy::pedantic,
clippy::nursery,
clippy::cargo,
clippy::unwrap_used,
clippy::expect_used
)]
use bitflags::bitflags;
use nessa_rom::{Mirroring, ROM};
use tracing::warn;
pub struct ShiftRegister {
bytes: [u8; 2],
index: usize,
}
impl ShiftRegister {
#[must_use]
pub const f... | true |
4d2cdb84f3c2ea3cc63aa9dca742c0c1d9e1512b | Rust | AKrill91/advent-of-code | /src/2020/day08.rs | UTF-8 | 6,024 | 3.34375 | 3 | [] | no_license | use std::collections::{HashSet, HashMap};
pub fn run_a(input: &Vec<String>) -> i64 {
let program = Program::from(input);
let mut execution = Execution::new(program);
let mut executed_instructions = HashSet::new();
let mut counter = execution.instruction_counter;
while !executed_instructions.cont... | true |
bf3740a4abae13245cf9633aa80ef5a4f35aacba | Rust | RaymarMonte/rust-exercism-solutions | /high-scores/src/lib.rs | UTF-8 | 865 | 3.078125 | 3 | [] | no_license | #[derive(Debug)]
pub struct HighScores {
scores: Vec<u32>,
}
impl HighScores {
pub fn new(scores: &[u32]) -> Self {
Self {scores: scores.to_vec()}
}
pub fn scores(&self) -> &[u32] {
self.scores.as_slice()
}
pub fn latest(&self) -> Option<u32> {
if self.scores.is_empty(... | true |
561221c84b19d0cae3e51f2b0a766f41a5878f66 | Rust | zmilan/tinychain | /host/src/object/mod.rs | UTF-8 | 4,878 | 2.984375 | 3 | [
"Apache-2.0"
] | permissive | //! User-defined object-orientation features.
use std::fmt;
use async_trait::async_trait;
use destream::{de, en, EncodeMap};
use futures::TryFutureExt;
use tc_error::TCResult;
use tc_transact::IntoView;
use tcgeneric::{label, path_label, NativeClass, PathLabel, PathSegment, TCPathBuf};
use crate::fs::Dir;
use crate... | true |
7719bb374ef3c92ed8c0078129577a059f947b39 | Rust | Spanfile/AoC-2018 | /src/input.rs | UTF-8 | 3,151 | 2.984375 | 3 | [] | no_license | use reqwest::header;
use std::fmt::Debug;
use std::fs;
use std::marker::PhantomData;
use std::path::Path;
use std::str::{FromStr, Lines, SplitWhitespace};
#[derive(Clone)]
pub struct Input {
input: String,
}
#[derive(Debug)]
pub struct ParsedLines<'a, T: FromStr>
where
T::Err: Debug,
{
lines_iter: Lines<'... | true |
ea2c7c54124f2ef98bfa2cc2953917b29d109126 | Rust | zacanger/lll | /src/commands/parent_directory.rs | UTF-8 | 1,613 | 2.578125 | 3 | [
"LGPL-3.0-only"
] | permissive | use crate::commands::{LllCommand, LllRunnable};
use crate::context::LllContext;
use crate::error::LllError;
use crate::history::DirectoryHistory;
use crate::window::LllView;
#[derive(Clone, Debug)]
pub struct ParentDirectory;
impl ParentDirectory {
pub fn new() -> Self {
ParentDirectory
}
pub cons... | true |
f893d8a36d84b00962ccb47b74599b0172d17ff6 | Rust | ntex-rs/ntex | /ntex/src/web/util.rs | UTF-8 | 9,058 | 2.984375 | 3 | [
"MIT"
] | permissive | //! Essentials helper functions and types for application registration.
use std::fmt;
use ntex_router::IntoPattern;
use crate::http::body::MessageBody;
use crate::http::error::{BlockingError, ResponseError};
use crate::http::header::ContentEncoding;
use crate::http::{Method, Request, Response};
use crate::service::{I... | true |
860b3b1776ddc3ea7933c0ec214155a9745deb82 | Rust | Spacebrook/quadtree | /quadtree/tests/test.rs | UTF-8 | 18,833 | 3.265625 | 3 | [
"Apache-2.0"
] | permissive | use quadtree::quadtree::{Config, QuadTree};
use quadtree::shapes::{Circle, Rectangle, ShapeEnum};
use rand::Rng;
use std::collections::HashSet;
#[test]
fn test_single_collision() {
let mut qt = QuadTree::new(Rectangle::new(0.0, 0.0, 100.0, 100.0));
qt.insert(
0,
ShapeEnum::Rectangle(Rectangle:... | true |
270f0b52bf2fb84c004f5dc5ba22c16db58bdac0 | Rust | mozilla/gecko-dev | /third_party/rust/icu_capi/src/bidi.rs | UTF-8 | 9,685 | 2.765625 | 3 | [
"LicenseRef-scancode-unicode",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | // This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
#[diplomat::bridge]
pub mod ffi {
use alloc::boxed::Box;
use alloc::vec::Vec;
use diplomat_runtime::Diplo... | true |
ce1c7fc24b590de8b035bf48e3150f6d7c64def3 | Rust | fluffypony/tari | /base_layer/core/src/chain_storage/memory_db/mem_db_vec.rs | UTF-8 | 5,569 | 2.515625 | 3 | [
"BSD-3-Clause"
] | permissive | // Copyright 2019. The Tari Project
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
// following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
// disclai... | true |
fbd34858a753987f5197321387a6cc5610dc9bd3 | Rust | rust-lang/rust | /tests/ui/wf/wf-in-fn-type-implicit.rs | UTF-8 | 951 | 3.078125 | 3 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"BSD-2-Clause",
"LicenseRef-scancode-unicode",
"MIT",
"LicenseRef-scancode-other-permissive"
] | permissive | // check-pass
// known-bug: #104005
// Should fail. Function type parameters with implicit type annotations are not
// checked for well-formedness, which allows incorrect borrowing.
// In contrast, user annotations are always checked for well-formedness, and the
// commented code below is correctly rejected by the bo... | true |
074250773b40b4a11794a288c01b4e9b235117e2 | Rust | tkygtr6/tutorials | /Rust-practice/linked_lists/single_linked_list/src/lib.rs | UTF-8 | 1,579 | 3.828125 | 4 | [] | no_license | use std::rc::Rc;
use std::cell::RefCell;
use std::mem;
struct Node {
val: i32,
next: Option<Box<Node>>
}
struct SingleLinkedList {
head: Box<Node>,
}
impl SingleLinkedList {
fn new() -> SingleLinkedList {
let mut head_node = Node{
val: -1,
next: None
};
... | true |
e4704d028bf8f6be3e639da357a105043a51ae99 | Rust | fulara/knw_share | /multi/src/x03_mutex.rs | UTF-8 | 2,120 | 3.578125 | 4 | [] | no_license | use std::thread;
use std::sync::Arc;
use std::thread::sleep_ms;
use std::sync::Mutex;
#[test]
fn mutex_silly_sample() {
let m = Mutex::new(5);
{
if let Ok(mut num) = m.lock() {
*num = 6;
}
}
println!("m = {:?}", m);
}
#[test]
fn mutex_sharing_data() {
// let mut v =... | true |
65a430b55617ac683582fb005d40b378798b478a | Rust | quodlibetor/cargo-readme | /src/helper.rs | UTF-8 | 7,030 | 3.125 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::env;
use std::io::{self, Write, ErrorKind};
use std::fs::File;
use std::path::{Path, PathBuf};
use cargo_info;
const DEFAULT_TEMPLATE: &'static str = "README.tpl";
/// Get the project root from given path or defaults to current directory
///
/// The given path is appended to the current directory if is a re... | true |
7fc176a7200fccfa2e2b941fe2a5b85200970947 | Rust | masonk/advent2017 | /src/13/13.1.rs | UTF-8 | 12,250 | 3.71875 | 4 | [] | no_license | // --- Day 13: Packet Scanners ---
// You need to cross a vast firewall. The firewall consists of several layers, each with a security scanner that moves back and forth across the layer. To succeed, you must not be detected by a scanner.
// By studying the firewall briefly, you are able to record (in your puzzle in... | true |
8fe498f668a49beb2e4d6524ee73786a9edc2f88 | Rust | webgl-fork/uni-glsl | /src/preprocessor.rs | UTF-8 | 24,560 | 2.75 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use nom::types::CompleteStr;
use nom::{space, Err, ErrorKind, IResult};
use nom::line_ending;
use std::convert::From;
use std::collections::HashMap;
use std::error;
use std::fmt;
use token::{identifier, token, BasicType, Constant, Identifier, Token};
use operator::Operator;
use defeval::{Eval, EvalContext, EvalError};
... | true |
9570761d006d3defafafe11f64e351f3921bd617 | Rust | amethyst/ludumdare42 | /game/src/utils/music.rs | UTF-8 | 342 | 2.703125 | 3 | [
"Apache-2.0"
] | permissive | use amethyst::audio::SourceHandle;
#[derive(Default)]
pub struct Music {
source: Option<SourceHandle>,
}
impl Music {
pub fn new(source: SourceHandle) -> Self {
Music {
source: Some(source),
}
}
pub fn next(&self) -> Option<SourceHandle> {
self.source.as_ref().map(... | true |
02f3b6322d1f6bb54f4f8b7c57b145aa871e52af | Rust | liclac/cardinal | /src/iso7816.rs | UTF-8 | 6,405 | 3.046875 | 3 | [] | no_license | use crate::{ber, util, Result};
use apdu::Command;
use pcsc::Card;
use tracing::{trace_span, warn};
pub fn select_name<'r, R: TryFrom<&'r [u8]>>(
card: &mut Card,
wbuf: &mut [u8],
rbuf: &'r mut [u8],
name: &[u8],
) -> Result<R, R::Error>
where
R::Error: From<crate::Error>,
{
Select {
id... | true |
f868b5472081af5352a9a4803e795db4967ebe63 | Rust | Icelk/beginner-programming-server | /src/main.rs | UTF-8 | 7,448 | 3.109375 | 3 | [
"MIT"
] | permissive | use kvarn::prelude::*;
// This below is a documentation comment.
// They exist in Rust and provide a way for you to add documentation to your types.
// Hover over the name `DATA_DIR` below to see the comment!
/// The data directory storing the lists.
const DATA_DIR: &str = "data";
#[tokio::main(flavor = "current_thre... | true |
246f5c8e8250955aac7a131ba0ac73baba65a2c8 | Rust | szy0syz/rust-demo | /src/m15_shadowing.rs | UTF-8 | 190 | 2.984375 | 3 | [] | no_license | pub fn fun() {
let mut x 10;
{
let x = 15;
}
let x = "X is a starting";
println!("x is {}", x); // -> X is a starting
let x = true;
println!("x is {}", x); // -> true
}
| true |
a76feccb4765533d87d6e11a76d691f89ab93424 | Rust | archer884/bsort | /src/lib.rs | UTF-8 | 1,649 | 3.890625 | 4 | [] | no_license | pub mod bsort {
use std::cmp::Ordering;
pub trait BSortable<T>
where T: PartialOrd
{
fn bsort(&mut self);
fn bsort_by<F: Fn(&T,&T) -> Ordering>(&mut self, f: F);
fn sorted<F: Fn(&T,&T) -> Ordering>(&self, f: &F) -> bool;
}
impl<T> BSortable<T> for Vec<T>
whe... | true |
fbb64283f8770759b185e84f8f986222c509ce42 | Rust | saltlick-crypto/saltlick-cli | /src/error.rs | UTF-8 | 5,471 | 2.625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"MIT"
] | permissive | // Copyright (c) 2020, Nick Stevens <nick@bitcurry.com>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/license/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distribute... | true |
30a8f460fcdeb7f4e2a5ab62ff86dc1179789b84 | Rust | h0gura/m5stack_hello_rust | /src/ili9341/gpio.rs | UTF-8 | 3,756 | 2.890625 | 3 | [] | no_license | use super::{Error, Interface};
use embedded_hal::digital::v2::OutputPin;
/// `Interface` implementation for GPIO interfaces
pub struct Gpio8Interface<'a, DATA, CSX, WRX, RDX, DCX> {
data_pins: &'a mut [DATA; 8],
csx: CSX,
wrx: WRX,
rdx: RDX,
dcx: DCX,
}
impl<'a, CSX, WRX, RDX, DCX, PinE>
Gpio8... | true |
347a16b7e5322d452463565be27f1d816b0bfaa6 | Rust | frozar/model | /hzv/codingame/rectangle_partition.rs | UTF-8 | 2,142 | 3.421875 | 3 | [] | no_license | use std::io;
macro_rules! parse_input {
($x:expr, $t:ident) => {
$x.trim().parse::<$t>().unwrap()
};
}
fn parse_input() -> (i32, i32, Vec<i32>, Vec<i32>) {
let mut input_line = String::new();
io::stdin().read_line(&mut input_line).unwrap();
let inputs = input_line.split(" ").collect::<Vec<... | true |
c75ded7712c6ea87e838be9c7bab01fa5bed35cb | Rust | ayberkt/rs-natural | /src/distance.rs | UTF-8 | 2,472 | 3.375 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"MIT"
] | permissive | struct CalcObjects<'a> {
first: &'a str,
second: &'a str,
}
impl<'a> CalcObjects<'a> {
fn max_length(&self) -> uint {
return if self.first.len() > self.second.len() {
self.first.len()
}
else {
self.second.len()
};
}
}
struct JaroWinkler<'a> {
co: CalcObjects<'a>,
matches1: Vec<... | true |
aad9804c2e075e8de0ccedca01dcc0a8b0d405bd | Rust | ericsink/rust-raytracer | /src/material/textures/checkertexture.rs | UTF-8 | 1,122 | 3.203125 | 3 | [
"MIT"
] | permissive | use crate::prelude::*;
use crate::material::Texture;
use crate::raytracer::compositor::ColorRGBA;
#[derive(Clone)]
pub struct CheckerTexture {
pub color1: ColorRGBA<f64>,
pub color2: ColorRGBA<f64>,
pub scale: f64 // Controls how large the squares are.
}
impl Texture for CheckerTexture {
fn color(&se... | true |
4b3adf29e25da649ddd2e588611190afae1aba1e | Rust | zonyitoo/irc-rs | /src/protocol/command/lusers.rs | UTF-8 | 1,564 | 2.8125 | 3 | [
"MIT"
] | permissive | use std::fmt;
use protocol::command::CMD_LUSERS;
use protocol::message::{IrcMessage, RawMessage, ParseMessageError};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct LusersCommand<'a> {
mask: Option<&'a str>,
target: Option<&'a str>,
}
impl<'a> LusersCommand<'a> {
pub fn new(mask_with_target: Option<(&'... | true |
bc422d241026e1703892d82c141c877d3e414501 | Rust | AustinHaugerud/oxidsys | /src/language/operations/presentation/create_slider_overlay.rs | UTF-8 | 964 | 2.59375 | 3 | [
"MIT"
] | permissive | use language::operations::{make_param_doc, Operation, ParamInfo};
pub struct CreateSliderOverlayOp;
const DOC : &str = "Creates horizontal slider overlay, with positions of the slider varying between min and max values. Current value of the slider can be changed with (overlay_set_val). Returns slider's overlay_id.";
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.