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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
8299f61977d5b9660086989983d9006473162c3d | Rust | no-reply/rust-rdf | /src/term/mod.rs | UTF-8 | 4,325 | 3.75 | 4 | [] | no_license | //! Structures for representing
//! [RDF Terms](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-term).
//!
//! # Examples
//!
//! ```
//! use rdf::term::*;
//!
//! let iri = IRI::new("http://example.com/moomin");
//! let node = BNode::new();
//! let literal = Literal::new("moomin", None, None);
//! ```
extern cra... | true |
a746e6d7205d5232bb404f8333eb98873b25f35b | Rust | U007D/is_type | /src/unit_tests.rs | UTF-8 | 459 | 2.859375 | 3 | [] | no_license | #[test]
fn empty_test() {}
#[test]
fn function_syntax_accepts_some_enum_as_some() {
let input = Some(42u8);
let expected_result = true;
assert!(is_type!(input, Some(_)) == expected_result);
}
#[test]
fn function_syntax_rejects_none_enum_as_some() {
#[allow(unused_qualifications)] //silences incorrect... | true |
844e6d56bd860a30a3aaa43816927ae645341f1e | Rust | dricketts/stateright | /src/actor/actor_test_util.rs | UTF-8 | 4,684 | 3.03125 | 3 | [
"MIT"
] | permissive | //! Utilities for actor tests.
/// A pair of actors that send messages and increment message counters.
pub mod ping_pong {
use crate::*;
use crate::actor::*;
use crate::actor::system::*;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum PingPongActor { PingActor { pong_id: Id }, PongActor }
#[d... | true |
9725e3ca7e04c6010a11a910bb9821aa879973e4 | Rust | julianandrews/adventofcode | /2021/rust/src/bin/day05.rs | UTF-8 | 3,163 | 3.390625 | 3 | [] | no_license | use std::collections::HashMap;
use aoc::aoc_error::AOCError;
use aoc::utils::{get_input, parse_fields};
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
fn main() -> Result<()> {
let input = get_input()?;
let lines: Vec<Line> = parse_fields(input.trim(), '\n')?;
println!("Part 1: {}"... | true |
1d5252d6f234d4d18c1d87536cc0e87ad6ea2585 | Rust | hellow554/stm32l4x6-memory-map | /src/wwdg.rs | UTF-8 | 5,861 | 3.015625 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # [ doc = "System window watchdog" ]
# [ repr ( C ) ]
pub struct Wwdg {
# [ doc = "0x00 - Control register" ]
pub cr: Cr,
# [ doc = "0x04 - Configuration register" ]
pub cfr: Cfr,
# [ doc = "0x08 - Status register" ]
pub sr: Sr,
}
# [ repr ( C ) ]
pub struct Cr {
register: ::volatile_regist... | true |
f1196308498420f8ad8f4215950b1ca11fe04c12 | Rust | danylaporte/rust-asyncplify | /src/filter.rs | UTF-8 | 2,477 | 3.328125 | 3 | [
"MIT"
] | permissive | use consumer::*;
use parallel_stream::*;
use stream::*;
struct FilterState<C, F> {
consumer: C,
predicate: F,
}
impl<C, F, T> Consumer<T> for FilterState<C, F>
where C: Consumer<T>,
F: FnMut(&mut T) -> bool
{
fn emit(&mut self, mut item: T) -> bool {
if (self.predicate)(&mut item) {
... | true |
303241bdbe8748f7bde364269804aa0c7888bc70 | Rust | GaiaWorld/pi_lib | /apm/src/counter.rs | UTF-8 | 9,333 | 2.6875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //! # 用于性能采集的计数器
//!
use std::time;
use std::thread;
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use lazy_static;
use fnv::FnvHashMap;
use parking_lot::RwLock;
use crossbeam_queue::ArrayQueue;
use pi_atom::Atom;
/*
* 最小动态计数器容量
*/
const MIN_DYNAMIC_COUNT... | true |
1e5dca6b36478babebde7c13445a97fbc3b355cd | Rust | rustyforks/tendril-wiki | /libs/render/src/tag_page.rs | UTF-8 | 776 | 2.765625 | 3 | [] | no_license | use tasks::CompileState;
use crate::{get_template_file, render_includes, Render};
pub struct TagPage {
pub title: String,
pub tags: Vec<String>,
}
impl TagPage {
pub fn new(title: String, tags: Vec<String>) -> Self {
TagPage { title, tags }
}
}
impl Render for TagPage {
fn render(&self, ... | true |
613d4548695e5e3d81bbe1c4b952cf3beb9b1738 | Rust | quote27/paperboids-rs | /src/octree.rs | UTF-8 | 12,371 | 3.203125 | 3 | [] | no_license | extern crate cgmath;
use aabb::AABB;
use boids::Boid;
use cgmath::{Vector3, Zero};
use std::usize;
/// Enum representing the Octnode's state.
/// - Empty: node hasn't been initialized
/// - Left: node contains a boid
/// - Node: node is an internal node
#[derive(Clone, Copy)]
pub enum OctnodeState {
Empty, // the... | true |
cdb9da031a2cef868a139a1374a710d258d1ea89 | Rust | pksunkara/reign | /reign_router/tests/methods.rs | UTF-8 | 8,799 | 2.640625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use reign_router::{
hyper::{body::to_bytes, Body, Method, Request as Req, StatusCode},
service, Error, Request, Response,
};
macro_rules! call {
($service:ident, $path:expr, $method:ident) => {
let res = $service
.clone()
.call(
Req::$method($path)
... | true |
a6221043e847066ae305a3bff68275fc5c31e096 | Rust | KonishchevDmitry/pyvsb-to-cloud | /src/storage/backup_group.rs | UTF-8 | 4,243 | 2.78125 | 3 | [] | no_license | use std::collections::HashSet;
use regex::{self, Regex};
use crate::core::GenericResult;
use crate::provider::{ReadProvider, FileType};
use super::backup::Backup;
use super::helpers::BackupFileTraits;
pub struct BackupGroup {
pub name: String,
pub backups: Vec<Backup>,
}
impl BackupGroup {
pub fn list(... | true |
7e516663d9681ae556a9b2dab1c080fd45d0d343 | Rust | redox-os/ion | /src/lib/assignments/checker.rs | UTF-8 | 6,120 | 3.390625 | 3 | [
"MIT"
] | permissive | use crate::{
expansion::{self, Expander},
parser::lexers::assignments::{Primitive, TypeError},
shell::variables::Value,
types,
};
use std::{iter::Iterator, rc::Rc};
/// Determines if the supplied value is either an array or a string.
///
/// - `[ 1 2 3 ]` = Array
/// - `[ 1 2 3 ][1]` = String
/// - `st... | true |
ef2db96d2dca4b9f1627310e3ab68c52b7c329ff | Rust | vincenthz/rust-pvss | /src/types.rs | UTF-8 | 964 | 2.59375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use crate::crypto::Scalar;
use core::num::NonZeroU32;
// threshold need to >= 2
pub type Threshold = u32;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct ShareId(NonZeroU32);
impl ShareId {
pub fn first() -> Self {
ShareId(NonZeroU32::new(1).unwrap())
}
pub fn next(self)... | true |
88885f3e35791140e529e222ecfd3f2e18a6b5a4 | Rust | nelhage/ultimattt | /src/main/selfplay.rs | UTF-8 | 3,600 | 3.03125 | 3 | [
"Apache-2.0"
] | permissive | use std::io;
use ultimattt::{game, minimax};
pub struct Executor<'a, F1, F2>
where
F1: Fn(game::Player) -> Result<Box<dyn minimax::AI + 'a>, io::Error>,
F2: Fn(game::Player) -> Result<Box<dyn minimax::AI + 'a>, io::Error>,
{
player1: F1,
player2: F2,
}
#[derive(Default)]
pub struct Results {
// (X... | true |
814273d3da3b40f6a7ceca599ccd62130f5f6946 | Rust | mfs/box | /src/main.rs | UTF-8 | 494 | 2.71875 | 3 | [] | no_license |
mod cpu;
mod rom;
mod ram;
mod hardware;
use std::env;
use std::fs;
use std::io::Read;
fn main() {
let rom_file_name = env::args().nth(1).unwrap();
let rom = read_rom(&rom_file_name);
let hardware = hardware::Hardware::new(rom);
let mut cpu = cpu::CPU::new(hardware);
cpu.run();
}
fn read_rom(... | true |
20a9419034eb6741b66b59e9199a6aed09cc19ea | Rust | vojtechkral/bard | /src/util/xml_support.rs | UTF-8 | 10,813 | 2.90625 | 3 | [
"Apache-2.0"
] | permissive | //! These are helpers defined on top of `quick_xml` to make XML serialization
//! of `book` AST easier.
//!
//! The `xml_write!` macro is essentially a poor man's `Derive`.
//!
//! The code here was needed as no existing XML derive crate is complete enough to cover bard AST requirements.
use std::borrow::Cow;
use std:... | true |
b59c03d51642f6325003d23cdc6dc11c5d461819 | Rust | YoYolops/controle-alunos | /rust/src/repositories/alunos.rs | UTF-8 | 1,124 | 3.25 | 3 | [] | no_license | use crate::models::aluno::Aluno;
use crate::errors::parameters::InvalidParameters;
pub struct RepositorioAlunos {
alunos: Vec<Aluno>
}
impl RepositorioAlunos {
pub fn new() -> RepositorioAlunos {
RepositorioAlunos {
alunos: Vec::new()
}
}
pub fn cadastrar_aluno(&mut self, ... | true |
d59fe2354f5c9a912010b76721c99dda0caf1d39 | Rust | Hugobros3/nes | /src/cpu.rs | UTF-8 | 3,959 | 2.71875 | 3 | [] | no_license | use crate::bus::Bus;
use crate::cpu::instructions::*;
use std::borrow::BorrowMut;
mod addressing_modes;
mod instructions;
/// NES 6502 CPU
/// No BCD support
#[derive(Debug)]
pub struct Cpu {
flags: CpuStateFlags,
a: u8,
x: u8,
y: u8,
stack_pointer: u8,
pub(crate) pc: u16,
rem_cycles: i8,... | true |
51e3b5da95211404a70eb109fbbc0137d2e4ffea | Rust | tsucchee/gravity_dataset | /src/state.rs | UTF-8 | 3,076 | 3.4375 | 3 | [] | no_license | #[derive(Copy, Clone, Debug)]
pub struct Position {
pub x: f64,
pub y: f64,
pub abs: f64,
}
impl Position {
#[inline]
fn set_abs(&mut self) {
self.abs = (self.x * self.x + self.y * self.y).sqrt();
}
#[inline]
pub fn predict(&mut self, vel: &Velocity, acc: &Acceleration, jerk: &... | true |
66006196062ab7b9c921881ed396e89843115d03 | Rust | ootsby-forks/learning_game_design_patterns | /ggez_infinite_runner/src/obstacle.rs | UTF-8 | 3,058 | 2.921875 | 3 | [] | no_license | use super::{Event, Observer, Player, PossibleObserver, Subject};
use ggez::graphics::{DrawMode, Mesh, MeshBuilder, WHITE};
use ggez::nalgebra::{Point2, Vector2};
use ggez::{Context, GameResult};
pub struct Obstacle {
location: Vector2<f32>,
location_to_reset_to: Vector2<f32>,
starting_location: Vector2<f32... | true |
d802e03729bc4bd2376868c6c28f45e97a7da04b | Rust | facebookexperimental/rust-shed | /shed/facet/test/params_test.rs | UTF-8 | 2,813 | 3.09375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | /*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under both the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree and the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree.
*/
pub... | true |
d8fdd2f101f25df04161929d923b54ade534305a | Rust | sdamashek/falcon | /lib/translator/hsvm/mod.rs | UTF-8 | 5,880 | 2.8125 | 3 | [
"Apache-2.0"
] | permissive | use il;
use error::Error;
struct Register {
name: &'static str,
encoding: u8
}
const REGISTERS : &'static [Register] = &[
Register {name: "r0", encoding: 0x0},
Register {name: "r1", encoding: 0x1},
Register {name: "r2", encoding: 0x2},
Register {name: "r3", encoding: 0x3},
Register {n... | true |
9979654ea22c180572863f181b0223492d7bf13f | Rust | kbogtob/rust-playground | /litegrep/src/lib.rs | UTF-8 | 1,335 | 3.21875 | 3 | [] | no_license | use std::{
fs::File,
io::{self, BufRead, BufReader, Write},
};
pub struct Config {
pattern: String,
input: Box<dyn BufRead>,
}
impl Config {
pub fn new(args: &[String]) -> Result<Config, &str> {
let pattern = args.get(1).ok_or_else(|| "Not enough arguments")?;
let filepath = args.g... | true |
02db819d24edeae74c01b74f832a8f91ad01c0a4 | Rust | dsbarnes/kanban-tui | /src/main.rs | UTF-8 | 9,777 | 2.875 | 3 | [] | no_license | mod util;
#[allow(unused_imports)]
use crate::util::{
StatefulList, TabsState,
event::{ Event, Events },
};
#[allow(unused_imports)]
use std::{error::Error, io};
#[allow(unused_imports)]
use termion::{event::Key, input::MouseTerminal, raw::IntoRawMode, screen::AlternateScreen};
#[allow(unused_imports)]
use ... | true |
409274c8ddca80889e59d44b6d71571c5ed08efc | Rust | mjochimsen/checksum | /src/sha512.rs | UTF-8 | 4,542 | 3.109375 | 3 | [] | no_license | use std::sync::Arc;
use openssl_sys::{
EVP_DigestFinal, EVP_DigestInit, EVP_DigestUpdate, EVP_MD_CTX_free,
EVP_MD_CTX_new, EVP_sha512, EVP_MAX_MD_SIZE, EVP_MD, EVP_MD_CTX,
};
use crate::{Background, Digest, DigestData, Generator};
/// A structure used to generate a SHA512 digest.
pub struct SHA512 {
/// ... | true |
3fec79c84e646f245126abfc56de755c2f7fea67 | Rust | bobbykaz/advent-of-code | /rust/src/years/y22/d10.rs | UTF-8 | 2,078 | 3.28125 | 3 | [
"MIT"
] | permissive | use core::panic;
use crate::util;
pub fn run() {
let lines = util::read_file_into_lines("../input/y22/d10.txt");
let cmds: Vec<CMD> = lines.iter().map(|x|parse_cmd(x)).collect();
let mut x: i64 = 1;
let mut cycle: i64 = 0;
let mut signals: Vec<i64> = vec![];
signals.push(0); //placeholder to ... | true |
91d0ac5e5746773fa676be29085fb87c4ffc81e8 | Rust | rukai/brawllib_rs | /src/resources.rs | UTF-8 | 1,246 | 2.828125 | 3 | [
"MIT"
] | permissive | use fancy_slice::FancySlice;
// ResourceGroup in brawlbox
#[rustfmt::skip]
pub(crate) fn resources(data: FancySlice) -> Vec<Resource> {
let total_size = data.i32_be(0);
let num_children = data.i32_be(4);
assert_eq!(total_size, (num_children + 1) * RESOURCE_SIZE as i32 + RESOURCE_HEADER_SIZE as i32);
... | true |
f326a0769e28e8df31f74d64a7bc0cb9e1f51c05 | Rust | Byron/gitoxide | /gix-prompt/examples/use-askpass.rs | UTF-8 | 375 | 2.625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use std::borrow::Cow;
use gix_prompt::{Mode, Options};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let pass = gix_prompt::ask(
"Password: ",
&Options {
askpass: Some(Cow::Owned(std::env::current_exe()?.parent().unwrap().join("askpass"))),
mode: Mode::Disable,
... | true |
23a90c1fff98de03a06e9833a0b0776c9af687c2 | Rust | njeisecke/umya-spreadsheet | /src/structs/cell_style.rs | UTF-8 | 796 | 3.09375 | 3 | [
"MIT"
] | permissive | use super::Style;
#[derive(Default, Debug)]
pub struct CellStyle {
name: String,
builtin_id: usize,
style: Style,
}
impl CellStyle {
pub fn get_name(&self)-> &str {
&self.name
}
pub fn set_name<S: Into<String>>(&mut self, value:S)-> &mut CellStyle {
self.name = value.into();
... | true |
e239f2ee5f84e802da8bbd81553f411404d1eff6 | Rust | vlamacko/rust-book | /variables/src/main.rs | UTF-8 | 900 | 3.796875 | 4 | [
"MIT"
] | permissive | fn main() {
/* Mutability */
let mut x = 5; // x must be mutable in order to change its value.
println!("The value of x is: {}", x);
x = 6;
println!("The value of x is: {}", x);
/* Constatnts
* - always immuatable.
* - must be set to a constant expression (known before runtime).
... | true |
a9e624af4c5955a2e49fe8d148adb84c15deddcd | Rust | omerbenamram/winstructs | /src/security/sec_desc.rs | UTF-8 | 4,997 | 2.578125 | 3 | [
"Apache-2.0"
] | permissive | use crate::err::Result;
use crate::security::acl::Acl;
use crate::security::sid::Sid;
use crate::ReadSeek;
use bitflags::bitflags;
use byteorder::{LittleEndian, ReadBytesExt};
use serde::Serialize;
use std::io::{Cursor, Read, SeekFrom};
#[derive(Serialize, Debug, Clone)]
pub struct SecurityDescriptor {
#[serde(s... | true |
6e4bd5b3abd05c46cbe2c133b2a212976167a282 | Rust | vaseemw/cuddly-waffle | /euler/src/math.rs | UTF-8 | 9,912 | 3.546875 | 4 | [] | no_license | // this module should hold the reusable pieces needed for each problem
// sub modules contain the implementation details for each problem.
// binaries are created in the bin directory for each problem to run, with benchmarking as necessary to compare implementations.
// sum of multiples under N
// n-1 / X rounded do... | true |
5dd4bcbe53063c74305768c22fe6a518308ffc09 | Rust | dungeonfog/pouchdb-rs | /src/lib.rs | UTF-8 | 19,845 | 2.78125 | 3 | [
"MIT"
] | permissive | use std::convert::{AsRef, TryFrom, TryInto};
use js_sys::{Array, Object, Reflect};
use wasm_bindgen::{JsCast, JsValue};
use wasm_bindgen_futures::JsFuture;
use web_sys::Blob;
mod pouchdb_sys;
use pouchdb_sys::PouchDB as JsPouchDB;
pub mod options;
use options::{
all_docs::AllDocsOptions, changes::Changes, create... | true |
78d12d6c7514a7fc19fb41623ae56fe3daca2c35 | Rust | Terkwood/BUGOUT | /micro-color-chooser/src/repo/prefs.rs | UTF-8 | 1,714 | 2.578125 | 3 | [
"MIT"
] | permissive | use super::*;
use core_model::SessionId;
use log::trace;
pub trait PrefsRepo {
fn get(&self, session_id: &SessionId) -> Result<Option<SessionColorPref>, FetchErr>;
fn put(&self, scp: &SessionColorPref) -> Result<(), WriteErr>;
}
impl PrefsRepo for Rc<Client> {
fn get(&self, session_id: &SessionId) -> Resu... | true |
39c86bd8d403858e095b5217c5ab548341017394 | Rust | rlipscombe/advent-2019 | /day4/src/main.rs | UTF-8 | 1,008 | 3.03125 | 3 | [] | no_license | fn main() {
let start = 197487;
let end = 673251;
let mut count = 0;
for x in start..=end {
let s = x.to_string();
if (s.contains("00") && !s.contains("000"))
|| (s.contains("11") && !s.contains("111"))
|| (s.contains("22") && !s.contains("222"))
|| (... | true |
67e6e120ecdb46393309525876e692bc12b07803 | Rust | sjb3d/aoc2020 | /src/day21.rs | UTF-8 | 3,469 | 2.984375 | 3 | [
"Unlicense"
] | permissive | use nom::{
bytes::complete::tag,
character::{complete::char, streaming::alpha1},
combinator::{all_consuming, map},
multi::separated_list1,
sequence::{delimited, tuple},
IResult,
};
use std::collections::{HashMap, HashSet};
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
struct Ingredient<'a>(&'a st... | true |
f61b7a6f72b9b14b96bd31659a83a773066370e6 | Rust | AudranDoublet/rtx_opr | /cubetracer/src/pipeline/command_buffers.rs | UTF-8 | 1,960 | 2.578125 | 3 | [] | no_license | use std::sync::Arc;
use crate::context::*;
use crate::window::*;
use ash::version::DeviceV1_0;
use ash::vk;
pub struct CommandBuffers {
context: Arc<Context>,
command_buffers: Vec<vk::CommandBuffer>,
}
impl CommandBuffers {
pub fn new(context: &Arc<Context>, swapchain: &Swapchain) -> Self {
let ... | true |
6219b09e8969eb42e20b61e550272c8f29c5741c | Rust | tolumide-ng/coding-challenge | /data_structures/src/recursion/n_queens.rs | UTF-8 | 2,672 | 3.640625 | 4 | [] | no_license | use std::fmt::Debug;
#[derive(Debug)]
struct Position {
row: i32,
col: i32,
}
#[derive(Debug)]
struct Queens {
total: i32,
positions: Vec<Position>,
n: i32,
}
pub fn total_n_queens(n: i32) -> i32 {
let mut queens = Queens::new(n);
queens.recursive_backtrack(0);
return queens.total;
}... | true |
1a4453283f15e0e9315e9a3b1415c053904df509 | Rust | songroom2016/katalyst | /src/config/builder/routes.rs | UTF-8 | 2,177 | 2.71875 | 3 | [
"MIT"
] | permissive | use super::*;
use crate::app::KatalystEngine;
use crate::error::KatalystError;
use crate::state::Route;
use http::Method;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::string::String;
use std::sync::Arc;
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
#[serde(d... | true |
371a54ffa6dab66424d0d1f68b79a75c72685719 | Rust | sky0621/study-rust | /old/fight-against-borrowed-checkers/temp3/src/main.rs | UTF-8 | 226 | 3.125 | 3 | [] | no_license | fn main() {
let g = Get {};
exec(&g);
}
trait Command {
fn run(&self);
}
struct Get {}
impl Command for Get {
fn run(&self) {
println!("Get!");
}
}
fn exec(cmd: &dyn Command) {
cmd.run();
}
| true |
8d23cf6fc089ada13d3292f7171a7ff0f1afc595 | Rust | hashmismatch/packed_struct.rs | /packed_struct/src/types_basic.rs | UTF-8 | 1,563 | 2.8125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use super::packing::*;
impl PackedStruct for bool {
type ByteArray = [u8; 1];
#[inline]
fn pack(&self) -> PackingResult<[u8; 1]> {
Ok(if *self { [1] } else { [0] })
}
#[inline]
fn unpack(src: &[u8; 1]) -> Result<bool, PackingError> {
match src[0] {
1 => Ok(true),
... | true |
da9c916432f171b486436ad5367ce5ebf092ec0d | Rust | diegoh/rust-learning-notes | /exercises/option-result/src/res.rs | UTF-8 | 597 | 3.59375 | 4 | [] | no_license | #[derive(Debug)]
pub enum Res<T, E> {
Thing(T),
Error(E),
}
fn divide(a: i32, b: i32) -> Res<i32, String> {
if b == 0 {
return Res::Error("Cannot divide by zero".to_string());
}
return Res::Thing(a / b);
}
fn main() {
let res = divide(100, 10);
let err = divide(10, 0);
// Best for multiple cases
... | true |
3891750a83b69ad61b0a1726f735c04b0debbaa9 | Rust | linpingchuan/pingchuan-mq | /src/parser.rs | UTF-8 | 5,379 | 2.90625 | 3 | [
"MIT"
] | permissive | use std::cell::RefCell;
use std::rc::Rc;
#[derive(Debug)]
pub struct PingchuanParser {}
#[derive(Debug, Clone)]
#[repr(transparent)]
pub struct PingchuanEvent {
request_content: String,
}
#[derive(Debug, Clone)]
pub struct PingchuanPacket {
pub transaction_id: u64,
pub topic_len: u64,
pub content_len: ... | true |
0a6a6d94f6d537c31fff53a169a5c6ccdd5b2d39 | Rust | 370417/tower-defense | /backend/src/walker.rs | UTF-8 | 12,107 | 3.09375 | 3 | [] | no_license | use serde::{Deserialize, Serialize};
use crate::{
distance::fast_distance,
graphics::{SpriteData, SpriteType},
map::{true_row_col, Constants, Tile, TRUE_MAP_WIDTH},
mob::Mob,
world::{Map, World},
};
pub const STANDARD_ENEMY_RADIUS: f32 = 0.3 * f32::TILE_SIZE;
/// A walker is an entity that travel... | true |
04a27bf01ff38a43084ad2272fe02d721b986d9a | Rust | diesel-rs/diesel | /diesel_compile_tests/tests/fail/pg_specific_expressions_cant_be_used_in_a_sqlite_query.rs | UTF-8 | 979 | 2.59375 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | extern crate diesel;
use diesel::dsl::*;
use diesel::sql_types::*;
use diesel::upsert::on_constraint;
use diesel::*;
table! {
users {
id -> Integer,
name -> VarChar,
}
}
sql_function!(fn lower(x: VarChar) -> VarChar);
#[derive(Insertable)]
#[diesel(table_name = users)]
struct NewUser(#[diese... | true |
18a8905f2d0ae203331a55ff0667f4b3bd9d1f1e | Rust | itn3000/hast | /src/check.rs | UTF-8 | 7,791 | 2.640625 | 3 | [
"MIT"
] | permissive | use super::ioutil;
use super::error::ApplicationError;
use digest::Digest;
use clap::ArgMatches;
use super::digestutil;
fn specialize_path_separator(input: &str) -> String {
input.replace("/", std::path::MAIN_SEPARATOR.to_string().as_str())
}
fn check_hash_fixed<D>(basepath: &str, inputfile: &str, expected_hash: ... | true |
0235f506aeecdfb749e6e361ef891135acc60b55 | Rust | vitvakatu/selfish | /src/lib.rs | UTF-8 | 11,633 | 2.8125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] | permissive | #[macro_use]
extern crate nom;
use std::collections::HashMap;
use std::cell::RefCell;
use std::rc::Rc;
mod core;
mod reader;
mod eval;
pub use reader::Reader;
pub use core::read_eval;
pub use core::standart_environment;
#[derive(Clone, Debug, PartialEq)]
pub struct Value(Rc<Type>);
pub type List = Vec<Value>;
#[... | true |
233c6a419d8cda6e9b2ef56a83b81aff55e756d1 | Rust | Gilthoniel/rust-rpc | /tests/counter.rs | UTF-8 | 2,165 | 3 | 3 | [
"MIT"
] | permissive | use std::sync::atomic::{AtomicU64, Ordering};
use rpc::Server;
use rpc::group::Address;
use rpc::transport::tcp::{
TcpClientTransport,
TcpServerTransport,
};
#[test]
#[should_panic(expected = "IncrementError")]
fn counter() {
#[derive(Serialize, Deserialize, Debug)]
pub enum CounterError {
Incr... | true |
9209d292dfd8c2e405adc75109757725e0660cdc | Rust | DRvader/AOC2020 | /src/bin/9/2.rs | UTF-8 | 637 | 2.8125 | 3 | [] | no_license | use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let buf = AOC2020::read_datafile("9.txt")?;
let nums: Vec<usize> = buf.lines().map(|l| l.parse().unwrap()).collect();
let target: usize = 22477624;
let mut root = 0;
let mut index = 0;
let mut sum = 0;
loop {
if sum > target... | true |
f6c4a01a3f825f89c801b680123e36ca1fd56077 | Rust | rust-skia/rust-skia | /skia-safe/src/interop/string.rs | UTF-8 | 3,242 | 2.859375 | 3 | [
"MIT"
] | permissive | use crate::prelude::*;
use skia_bindings::{self as sb, SkString};
use std::{fmt, str};
pub type String = Handle<SkString>;
unsafe_send_sync!(String);
impl NativeDrop for SkString {
fn drop(&mut self) {
unsafe {
sb::C_SkString_destruct(self);
}
}
}
impl AsRef<str> for String {
... | true |
b4c908c8b21e58b8dc01fbfd0b14b3e05167ca2b | Rust | stickeritis/sticker-python | /src/util.rs | UTF-8 | 962 | 2.9375 | 3 | [] | no_license | use std::ops::{Deref, DerefMut};
use pyo3::exceptions;
use pyo3::prelude::*;
use pyo3::types::{PyAny, PyList};
/// A `Vec` that that can only be converted from a Python list.
pub struct ListVec<T> {
inner: Vec<T>,
}
impl<T> ListVec<T> {
/// Get wrapped `Vec`.
pub fn into_inner(self) -> Vec<T> {
s... | true |
1e3beb5901186f30d66c2b93bc25442f664dcd12 | Rust | bfollek/advent2018rust | /src/main.rs | UTF-8 | 558 | 2.5625 | 3 | [] | no_license | mod day_01;
mod day_02;
mod util;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
// Day 1
assert_eq!(592, day_01::part_1("testdata/day01.txt")?);
assert_eq!(592, day_01::part_1_fold("testdata/day01.txt")?);
assert_eq!(592, day_01::part_1_sum("testdata/day01.txt")?);
assert_eq!(24... | true |
a749f4e5098bc3b3cab52cf07b5fddff548cbbfd | Rust | Kayren/wardice | /src/lib.rs | UTF-8 | 6,852 | 3.078125 | 3 | [] | no_license | #![deny(
missing_docs, missing_debug_implementations, trivial_casts, trivial_numeric_casts, unsafe_code, unstable_features, unused_import_braces,
unused_qualifications
)]
//! Wardice crate
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate rand;
extern crate serde_json;
use rand::{threa... | true |
e0116c22ce243b0f7a30e5ce1789db69830e20f3 | Rust | sgr2848/nolang | /src/lexer.rs | UTF-8 | 8,977 | 3.46875 | 3 | [] | no_license | #![allow(dead_code,unused_imports)]
use regex::Regex;
use std::collections::{HashMap, VecDeque};
use std::string::String;
#[derive(Debug, Clone, Copy, PartialEq, Eq,Hash)]
pub enum Type {
/*
*The type of token to return to interpreter
*/
Digits,
Identifier,
Plus,
Minus,
Divide,
Le... | true |
69fddab88540c09892c1b2226012d56aaf90e72f | Rust | Hack998/Extraclase_2 | /Adapter Rust/Adapter.rs | UTF-8 | 781 | 3.453125 | 3 | [] | no_license | trait Play {
fn play(&self);
}
struct IPlayer ();
impl Play for IPlayer{
fn play(&self){
}
}
trait OldPlay {
fn oldPlay(&self);
}
struct OldPlayer{
song : String,
volume : i32
}
impl OldPlayer {
fn new(song: &str, volume: &i32) -> OldPlayer {
OldPlayer {
song: song.to_string(),
volume: *volume
... | true |
af3d41b3646b59effbaaa65c3e2eb7a01caa5e96 | Rust | fleuryz/Focus | /src/respostaSN.rs | UTF-8 | 792 | 3.671875 | 4 | [] | no_license | use std::io;
pub enum RespostaSN {
SIM,
NAO,
}
impl RespostaSN {
pub fn new(pergunta: &str) -> RespostaSN {
let mut resposta = String::new();
loop {
println!("{}(S/n)", pergunta);
io::stdin().read_line(&mut resposta)
.expect("Erro ao ler pergunta de ... | true |
010882d43cc57f12a0dbc1aa1ad4a77b3a574e0b | Rust | mariomurillo/bike_shop | /bike/src/controller/bike_controller.rs | UTF-8 | 2,054 | 2.90625 | 3 | [] | no_license | use actix_web::{Responder, HttpResponse, get, post, put, delete, web};
use crate::controller::model::bike::Bike;
use super::super::service::model::bike::Bike as BikeDomain;
use crate::bike_app::BikeApp;
#[get("/bike")]
pub async fn get_bikes(data: web::Data<BikeApp>) -> impl Responder {
let service = data.service.... | true |
036e6a3b417a42cd8cded11875b2a9b6239a3b4d | Rust | ummarikar/yksom | /src/lib/vm/objects/mod.rs | UTF-8 | 5,139 | 3.515625 | 4 | [
"MIT",
"Apache-2.0"
] | permissive | //! This module contains the core SOM objects. Note that there is a fundamental constraint that
//! *must* be obeyed by the programmer at all times: upon their creation, instances of the `Obj`
//! trait must immediately be passed to `Val::from_obj`. In other words this is safe:
//!
//! ```rust,ignore
//! let x = Val::f... | true |
a30207eafc221b754aeb5a12b1a58a1b9471ebbf | Rust | etandel/adventofcode | /2015/d6/src/main.rs | UTF-8 | 4,464 | 3.34375 | 3 | [] | no_license | use std::env;
use std::fs;
use std::path::Path;
use std::str::FromStr;
#[derive(Debug, PartialEq, Eq)]
enum Op {
TurnOn,
TurnOff,
Toggle,
}
impl FromStr for Op {
type Err = ();
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
Ok(match s {
"on" => Self::TurnOn,
... | true |
60a1e7356425261d6add3db02f2743fdd9ad054b | Rust | EFanZh/LeetCode | /src/problem_1515_best_position_for_a_service_centre/geometric_median.rs | UTF-8 | 2,074 | 3.3125 | 3 | [] | no_license | pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //
// See <https://en.wikipedia.org/wiki/Geometric_median>.
use std::convert::TryInto;
use std::f64::consts;
impl Solution {
fn iterate(positions: &[(f64, f64)], guess: (f64... | true |
854c611d436e7532ab727c1b9da319902ec81863 | Rust | bnjjj/apollo-rs | /crates/apollo-parser/src/parser/grammar/variable.rs | UTF-8 | 10,884 | 2.921875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use crate::{
parser::grammar::{directive, name, ty, value},
Parser, SyntaxKind, TokenKind, S, T,
};
/// See: https://spec.graphql.org/draft/#VariableDefinitions
///
/// *VariableDefinitions*:
/// **(** VariableDefinition<sub>list</sub> **)**
pub(crate) fn variable_definitions(p: &mut Parser) {
let _g =... | true |
cf7f1f754df409b5b1d729390a09a3464383c081 | Rust | marco-c/gecko-dev-wordified | /third_party/rust/num-integer/benches/roots.rs | UTF-8 | 3,648 | 2.5625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | /
/
!
Benchmark
sqrt
and
cbrt
#
!
[
feature
(
test
)
]
extern
crate
num_integer
;
extern
crate
num_traits
;
extern
crate
test
;
use
num_integer
:
:
Integer
;
use
num_traits
:
:
checked_pow
;
use
num_traits
:
:
{
AsPrimitive
PrimInt
WrappingAdd
WrappingMul
}
;
use
test
:
:
{
black_box
Bencher
}
;
trait
BenchInteger
:
In... | true |
a05014f142aef780940f3be00deb7842e6d8b910 | Rust | idheepan/max31856-rs | /src/lib.rs | UTF-8 | 9,507 | 2.984375 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Rust driver for MAX31856
//!
//! Uses [`embedded-hal`] traits and patterns from Eldruin's [`driver-examples`]
//!
//! [`embedded-hal`]: https://github.com/rust-embedded/embedded-hal
//! [`driver-examples`]: https://github.com/eldruin/driver-examples
//!
//! Features:
//! - Modify default configuration. see [`config... | true |
dba4628abd61be953191970c3ea4255bb083c496 | Rust | wose/urii | /src/urlinfo.rs | UTF-8 | 2,561 | 2.609375 | 3 | [] | no_license | use bot::MsgHandler;
use hyper::header::{UserAgent, ContentType};
use hyper::mime::{Mime, TopLevel, SubLevel};
use irc::client::prelude::*;
use marksman_escape::Unescape;
use regex::Regex;
use reqwest;
use std::io::Read;
use std::str;
pub struct UrlInfoPlugin {
url_re: Regex,
title_re: Regex,
}
impl UrlInfoPl... | true |
de656124fbd15debbb3142a5a745884daff8fdd6 | Rust | stevelr/mdsite | /src/render.rs | UTF-8 | 10,148 | 3.0625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! HTML generation
//!
use crate::{Result, TomlMap};
use chrono::DateTime;
use handlebars::Handlebars;
use serde_json::Value as JsonValue;
use std::collections::HashMap;
use toml::value::Value as TomlValue;
/// Html to insert before and after diff chunks
pub struct DiffStyle {
/// Html to insert before a span of ... | true |
16df3190fcce592b0229070e1594286b3a0c8c38 | Rust | paritytech/substrate | /frame/nfts/src/features/create_delete_collection.rs | UTF-8 | 5,530 | 2.609375 | 3 | [
"Apache-2.0",
"GPL-3.0-or-later",
"Classpath-exception-2.0",
"GPL-1.0-or-later",
"GPL-3.0-only"
] | permissive | // This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// 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.a... | true |
719c01ecf6231e710ad39c95d80c67d4f9f7cbc6 | Rust | frankegoesdown/LeetCode-in-Go | /Algorithms/0874.walking-robot-simulation/walking-robot-simulation.go | UTF-8 | 3,039 | 2.921875 | 3 | [
"MIT"
] | permissive | package problem0874
var dxs = []int{0, 1, 0, -1}
var dys = []int{1, 0, -1, 0}
func robotSim(commands []int, obstacles [][]int) int {
isBlocked := make(map[int]bool, 10000)
for _, o := range obstacles {
i, j := o[0], o[1]
isBlocked[encode(i, j)] = true
}
x, y, res := 0, 0, 0
index := 0
for _, c := range co... | true |
d063f0948c82e2fb7124385a1db1cb99da9ad35f | Rust | shadowsocks/shadowsocks-rust | /crates/shadowsocks-service/src/local/tun/udp.rs | UTF-8 | 5,526 | 2.53125 | 3 | [
"MIT"
] | permissive | use std::{
io::{self, ErrorKind},
net::{IpAddr, SocketAddr},
sync::Arc,
time::Duration,
};
use async_trait::async_trait;
use bytes::{BufMut, BytesMut};
use etherparse::PacketBuilder;
use log::{debug, trace};
use shadowsocks::relay::socks5::Address;
use tokio::sync::mpsc;
use crate::{
local::{
... | true |
17dc6c4dae9c8af1f4fe0a040892366e2f27a523 | Rust | krtab/diff | /src/std_ops.rs | UTF-8 | 3,444 | 3.109375 | 3 | [] | no_license | use std::ops::{Add, Mul};
use crate::{
op_struct::{Addition, Multiplication},
scalar::Scalar,
Expr,
};
use super::{Diff, Variable};
impl<'a, T, V> Add<T> for &'a Variable<V>
where
V: Scalar,
T: Expr<ValueType = V>,
{
type Output = Addition<Self, T, V>;
fn add(self, rhs: T) -> Self::Outpu... | true |
e3b1e2439aedc193a055ecb9dba426360cbcf2e9 | Rust | tatsuya-sato-tesseract/generic-game | /zomes/main/code/src/game.rs | UTF-8 | 16,306 | 3.109375 | 3 | [] | no_license | use std::convert::TryFrom;
use hdk::{
utils,
entry_definition::ValidatingEntryType,
error::{ZomeApiResult, ZomeApiError},
holochain_persistence_api::{
cas::content::{AddressableContent, Address},
},
holochain_json_api::{
error::JsonError, json::JsonString,
},
holochain_co... | true |
c5a43f342207c0f2f05db0a1b6cdc1da1c310549 | Rust | danthedaniel/rangetype | /src/macros.rs | UTF-8 | 273 | 3 | 3 | [
"MIT"
] | permissive | /// Create a RangeType and employ static checks on its value.
#[macro_export]
macro_rules! range {
($val:expr, $range:expr) => {
{
const_assert!($val >= $range.start && $val <= $range.end);
RangeType::new($val, $range)
}
}
}
| true |
33245d443d900fb0bbfbd37cecf549c2c66579f2 | Rust | nickdonnelly/horus-server | /src/models/himage.rs | UTF-8 | 2,613 | 2.765625 | 3 | [] | no_license | use chrono::NaiveDateTime;
use diesel::prelude::*;
use diesel::pg::PgConnection;
use schema::horus_images;
use models::traits::passwordable;
#[derive(AsChangeset, Queryable, Serialize, Identifiable, Insertable)]
#[table_name = "horus_images"]
pub struct HImage
{
pub id: String,
pub title: Option<String>,
... | true |
1d6a0fbb2e3a72023a79b783659947cf363d8f11 | Rust | MechanicalPython/adafruit_gps | /src/pmtk.rs | UTF-8 | 39,089 | 3.109375 | 3 | [
"MIT"
] | permissive | //! PMTK commands give the gps module settings for output.
//!
//! To give a PMTK command send it via the Gps struct: gps.pmtk....(args). See simple.rs for example.
//!
//! Note:
//! All commands will be destructive for all sentences in the buffer. You will not be able to read data given by
//! the gps after sending it... | true |
9ea41e8ea39e6da5f06c9b6f9b8e89893287047d | Rust | hr6134/ctchi | /src/main.rs | UTF-8 | 1,277 | 2.71875 | 3 | [
"BSD-3-Clause"
] | permissive | #![feature(concat_idents)]
mod utils;
use ctchi::core::app::Ctchi;
use ctchi::core::routes::{Routes, Route};
use ctchi_codegen::route;
use std::collections::HashMap;
use ctchi::templates::parser::Context;
#[route("/")]
fn index()-> String {
let mut context = HashMap::<String, Context>::new();
context.insert(... | true |
fe40571c9cf233f0e24a25c6e15aa7e8dacd0565 | Rust | xdd666t/rust_use | /src/leet_code/easy/two_sum.rs | UTF-8 | 1,060 | 4 | 4 | [] | no_license | use std::collections::HashMap;
/// 给定一个整数数组 nums和一个整数目标值 target,请你在该数组中找出和为目标值 target 的那两个整数,并返回它们的数组下标。
/// 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。
///
/// 你可以按任意顺序返回答案。
/// 输入:nums = [2,7,11,15], target = 9
/// 输出:[0,1]
/// 解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。
pub fn main() {
let num = Solution::two_sum(ve... | true |
6c539f20baee0418a8c1e1a6932b39287f54c88e | Rust | varqox/prover | /parser/src/formula.rs | UTF-8 | 3,326 | 3.21875 | 3 | [] | no_license | // Author: Michał Niciejewski
use pest::Parser;
use pest::error::Error;
#[derive(Parser)]
#[grammar = "grammar.pest"]
struct FormulaParser;
#[derive(Hash, Eq, Debug, Clone)]
pub enum GenTerm<VarType> {
Var(VarType),
Fun(String, Vec<GenTerm<VarType>>),
}
impl<VarType: std::cmp::PartialEq> PartialEq for GenTer... | true |
6d0912d5211e9901c3d690b6daba1f36ea797e0c | Rust | blabaere/mio-win-inv | /src/named_pipe.rs | UTF-8 | 5,865 | 2.84375 | 3 | [] | no_license | use std::thread;
use std::time;
use std::io::{Write, Read};
use mio::*;
use mio_named_pipes::NamedPipe;
use winapi;
use std::fs::OpenOptions;
use std::os::windows::fs::*;
use std::os::windows::io::*;
macro_rules! t {
($e:expr) => (match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", strin... | true |
b071b5d90d651c1d8a96122416c01ece2fd8a0f8 | Rust | sajahe/cellular-automata-rust | /src/elementary.rs | UTF-8 | 2,184 | 3.203125 | 3 | [] | no_license | extern crate image;
extern crate bit_array;
extern crate typenum;
extern crate rand;
use image::RgbImage;
use bit_array::BitArray;
use typenum::U8;
use elementary::rand::prelude::*;
pub fn create_image(rule: u8){
let dx = 1028;
let dy = 1028;
println!("Using {}", rule);
let mut img = RgbImage::new(dx,... | true |
2b34de003f3b49a119fb43f62debe8753874377e | Rust | google/tock-on-titan | /third_party/pin-utils/src/projection.rs | UTF-8 | 2,501 | 3.9375 | 4 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"LicenseRef-scancode-generic-cla"
] | permissive | /// A pinned projection of a struct field.
///
/// To make using this macro safe, three things need to be ensured:
/// - If the struct implements [`Drop`], the [`drop`] method is not allowed to
/// move the value of the field.
/// - If the struct wants to implement [`Unpin`], it has to do so conditionally:
/// The ... | true |
e69c9aafb8b6d27e04e1a12bef9886197499601e | Rust | douweschulte/pdbtbx | /src/reference_tables.rs | UTF-8 | 3,763 | 2.890625 | 3 | [
"MIT"
] | permissive | #[cfg(feature = "rayon")]
use rayon::prelude::*;
/// Gets the index (into Int. Crys. Handbook Vol A 2016) for the given symbol. First it is
/// interpreted as a Herman Mauguin symbol, if that is unsuccessful it is interpreted as a
/// Hall symbol.
pub fn get_index_for_symbol(symbol: impl AsRef<str>) -> Option<usize> {... | true |
77a2fdb9a219047b56af76d7c9dec5fb5b26195d | Rust | mgsloan/nightwriter | /src/config.rs | UTF-8 | 7,357 | 2.71875 | 3 | [] | no_license | use crate::mod_keys::ModKeys;
use dirs;
use failure::Error;
use serde::de;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::collections::HashMap;
use std::fmt;
use std::fs;
use std::io::ErrorKind;
use std::path::PathBuf;
use std::string::String;
use std::vec::Vec;
#[derive(Serialize, Deserialize... | true |
31e499901240ab26bfe450dfb869798a02fcc36b | Rust | justinliew/aoc2018 | /src/day4.rs | UTF-8 | 3,873 | 3.109375 | 3 | [] | no_license | use std::fs::File;
use std::io::prelude::*;
use std::collections::BTreeMap;
use std::collections::HashMap;
extern crate regex;
use self::regex::Regex;
#[derive(Eq,Ord,PartialOrd,PartialEq,Debug)]
struct Time {
year: i32,
month: i32,
day: i32,
hour: i32,
min: i32,
}
#[derive(Debug... | true |
2f3a86606bd3c2015087ee445a740196fba66b7f | Rust | liljencrantz/crush | /src/lib/math.rs | UTF-8 | 3,959 | 2.984375 | 3 | [
"MIT"
] | permissive | use crate::lang::command::OutputType::Known;
use crate::lang::errors::CrushResult;
use crate::lang::state::contexts::CommandContext;
use crate::lang::state::scope::Scope;
use crate::lang::value::Value;
use crate::lang::value::ValueType;
use signature::signature;
use crate::lang::signature::number::Number;
macro_rules!... | true |
cd04e780e021ffe913fb01dcc9c8320ad32e26df | Rust | csu-xiao-an/tiger-rs | /tiger/src/error.rs | UTF-8 | 5,624 | 2.65625 | 3 | [] | no_license | /*
* Copyright (c) 2017-2019 Boucher, Antoni <bouanto@zoho.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, ... | true |
297e6ba77e712e76cca8b8f3c0f580d612d806cc | Rust | MSRG/libra | /ol/txs/src/save_tx.rs | UTF-8 | 2,132 | 2.984375 | 3 | [
"Apache-2.0"
] | permissive | //! `save tx`
use anyhow::Error;
use diem_types::transaction::SignedTransaction;
use std::{
fs::{self, File},
io::{BufReader, Write},
path::PathBuf,
};
/// Save signed transaction to file
pub fn save_tx(txn: SignedTransaction, path: PathBuf) {
let vec = vec![txn];
save_batch_tx(vec, path);
}
/// TODO: save ... | true |
fcee250143a513510969e03007374a71a6cfe295 | Rust | LucasPickering/osrs-cli | /src/utils/table.rs | UTF-8 | 924 | 3.015625 | 3 | [
"MIT"
] | permissive | use comfy_table::{Cell, CellAlignment, Table};
/// Additional functionality for the [Table](comfy_table::Table) type
pub trait TableExt {
/// Set the headers of a table in conjunction with an alignment for each
/// column
fn set_aligned_header<T: Into<Cell>>(
&mut self,
headers: impl IntoIt... | true |
bd8fb8cc7b0805341cc85092ef4a944f0cba30ea | Rust | stackcats/leetcode | /algorithms/easy/excel_sheet_column_number.rs | UTF-8 | 216 | 2.84375 | 3 | [
"MIT"
] | permissive | impl Solution {
pub fn title_to_number(s: String) -> i32 {
let mut ans = 0;
for c in s.chars() {
let n = (c as i32) - 64;
ans = ans * 26 + n;
}
ans
}
}
| true |
b4b670c59f941ad57e93a38d660f485eeb159594 | Rust | xu-cheng/aoc19 | /src/bin/day15.rs | UTF-8 | 3,440 | 3.15625 | 3 | [
"MIT"
] | permissive | use aoc2019::computer::*;
use aoc2019::*;
use std::collections::{HashSet, VecDeque};
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
enum Direction {
N = 1,
S = 2,
W = 3,
E = 4,
}
use Direction::*;
impl Into<i64> for Direction {
fn into(self) -> i64 {
match self {
N => 1,
... | true |
e023ad4523388d68db835535c28c788b47aaf308 | Rust | scottjmaddox/rust-game-boilerplate | /dev-client/src/loop_context.rs | UTF-8 | 3,413 | 2.828125 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | // Copyright 2018, Scott J Maddox
//
// 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... | true |
598ca04f69ea3698f9b565b8bc1cf1b37e4ba45a | Rust | appcypher/wasmo-old | /lib/llvm/src/values/function.rs | UTF-8 | 2,740 | 2.796875 | 3 | [
"Apache-2.0"
] | permissive | use super::Value;
use llvm_sys::core::{
LLVMAppendBasicBlockInContext, LLVMCountParams, LLVMGetFirstParam, LLVMGetLastParam,
LLVMGetParam, LLVMSetLinkage,
};
use llvm_sys::prelude::LLVMValueRef;
use crate::{BasicBlock, Context, Linkage};
use super::{
super::{
errors::{GetValue, GetType}, Compiler... | true |
c3a4e424b85669968b5537a5ab50001c4e48662e | Rust | glatan/ghash | /crate/hash/sha0/src/default.rs | UTF-8 | 2,921 | 2.6875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use alloc::vec::Vec;
use core::cmp::Ordering;
use util::{impl_md_flow, uint_from_bytes, Hash};
use crate::consts::{ch, maj, parity, IV, K};
macro_rules! init_w {
( $w:expr, $( $t:expr ),* ) => {
$(
$w[$t] = $w[$t - 3] ^ $w[$t - 8] ^ $w[$t - 14] ^ $w[$t - 16];
)*
};
}
macro_rules!... | true |
b9cdd6f41a205e0527e1cb4775b04f3dc213aa81 | Rust | cdepillabout/saabanto | /src/lib.rs | UTF-8 | 4,378 | 3.828125 | 4 | [] | no_license |
/// This is a very rough sketch of what a fully type-safe REST JSON API could look like in Rust,
/// where the server, client, and documentation are all generated programatically. The only thing
/// you have to actually write is the API, and the individual type-safe handlers.
/// These are some simple types that ar... | true |
745860a0833e2a1148189a7e6874f36c619a5ce0 | Rust | ipetkov/conch-parser | /tests/if.rs | UTF-8 | 10,373 | 2.609375 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #![deny(rust_2018_idioms)]
use conch_parser::ast::builder::*;
use conch_parser::parse::ParseError::*;
use conch_parser::token::Token;
mod parse_support;
use crate::parse_support::*;
#[test]
fn test_if_command_valid_with_else() {
let guard1 = cmd("guard1");
let guard2 = cmd("guard2");
let guard3 = cmd("gua... | true |
9c42dfd2dbd8c26a14d04fdf316a2e9dfb00fd21 | Rust | holsee/bloom_spell | /src/main.rs | UTF-8 | 375 | 2.546875 | 3 | [] | no_license | extern crate bloom_spell;
use bloom_spell::util::bloom_filter::BloomFilter;
fn main() {
let bf = {
let mut bf = BloomFilter::new(1000, 20);
bf.insert("wow");
bf.insert("wee");
bf
};
let wow = bf.maybe_contains("wow");
println!("wow = {:#?}", wow);
let foo = bf.mayb... | true |
75ef867f1213b9ffff1ecea252bcc8a9ce2f306e | Rust | cozydate/rust-in-production | /example/src/main.rs | UTF-8 | 1,998 | 3.46875 | 3 | [
"MIT"
] | permissive |
struct IncrementingSource {
value: u8,
}
impl IncrementingSource {
pub fn new(value: u8) -> IncrementingSource {
IncrementingSource { value }
}
pub async fn get_and_increment(&mut self) -> u8 {
let result = self.value;
self.value += 1;
result
}
}
struct Holder {
... | true |
845911752741a97edaf198bb2f0838ce682dab6f | Rust | AGoetzDev/advent_of_code_2018 | /src/day12.rs | UTF-8 | 4,443 | 3.09375 | 3 | [] | no_license | use std::{
fmt::{self, Display},
iter::FromIterator,
};
fn fmt_pot(pot: bool) -> char {
if pot {
'#'
} else {
'.'
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Transition {
input: Vec<bool>,
output: bool,
}
impl Display for Transition {
fn fmt(&self, f: &mut fm... | true |
4cf4485bc3282107a33802446e5c2cd106256baa | Rust | awakecoding/treexml-rs | /src/lib.rs | UTF-8 | 13,285 | 3.28125 | 3 | [
"MIT"
] | permissive | //! An element-tree style XML library
//!
//! # Examples
//!
//! ## Reading
//!
//! ```
//! use treexml::Document;
//!
//! let doc_raw = r#"
//! <?xml version="1.1" encoding="UTF-8"?>
//! <table>
//! <fruit type="apple">worm</fruit>
//! <vegetable />
//! </table>
//! "#;
//!
//! let doc = Document::parse(doc_ra... | true |
6174cc6eb07a4f3641980510b8f8c2c8950973c3 | Rust | rust-bitcoin/rust-bitcoin | /bitcoin/src/parse.rs | UTF-8 | 6,356 | 3.109375 | 3 | [
"CC0-1.0",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | // SPDX-License-Identifier: CC0-1.0
use core::convert::TryFrom;
use core::fmt;
use core::str::FromStr;
use internals::write_err;
use crate::error::impl_std_error;
use crate::prelude::*;
/// Error with rich context returned when a string can't be parsed as an integer.
///
/// This is an extension of [`core::num::Par... | true |
4734cde744b516218f252d5e67f2ade987bb2c0d | Rust | PrateekKSingh/Potential-Cadaver-organ-causing-event-tracking-and-waiting-list-management-on-Blockchain | /lib.rs | UTF-8 | 5,132 | 3.078125 | 3 | [] | no_license | #![cfg_attr(not(feature = "std"), no_std)]
use ink_lang as ink;
#[ink::contract]
mod CadavericKidneyWaitlist {
/// Defines the storage of your contract.
/// Add new fields to the below struct in order
/// to add new static storage fields to your contract.
#[ink(storage)]
pub struct CadavericKidne... | true |
2c6be5af01b2b967ab601ceec49eae35d2acf1f3 | Rust | hueypeard/rgit | /src/packfile/refs.rs | UTF-8 | 2,180 | 3.21875 | 3 | [] | no_license | use std::io::Result as IoResult;
use std::io::Write;
use std::fs;
use std::fs::File;
use std::path::{Path,PathBuf};
#[derive(Debug)]
pub struct GitRef {
pub id: String,
pub name: String,
}
pub fn create_refs(repo: &str, refs: &[GitRef]) -> IoResult<()> {
let (tags, branches): (Vec<_>, Vec<_>) = refs.iter(... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.