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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
4758f0cb0e72883d91e5050e9a2ffdf903e19b9f | Rust | arewei/learn_rust | /src/test/find_file.rs | UTF-8 | 1,356 | 2.578125 | 3 | [] | no_license | extern crate error_chain;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use error_chain::error_chain;
use glob::glob;
// use walkdir::WalkDir;
#[allow(dead_code)]
pub fn is_pic(path: &str) -> bool {
path.contains(".png") ||
path.contains(".jpeg") || path.contains(".jpg")
... | true |
05829d6689d54ced72133880aec7a201dbf0e2be | Rust | scotow/minecrust | /src/types/string.rs | UTF-8 | 1,632 | 2.890625 | 3 | [] | no_license | use crate::types::{self, FromReader, Receive, Send, Size, TAsyncRead, TAsyncWrite};
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use futures::prelude::*;
use futures::AsyncWriteExt;
use std::ops::Deref;
use std::string::String as StdString;
#[derive(Debug, Clone)]
pub struct String(StdString);
impl Str... | true |
5242eaafbc9c4f68a7b01634dcbf15887194ccba | Rust | macisamuele/loader-rs | /src/loader/trait_.rs | UTF-8 | 3,177 | 3 | 3 | [
"MIT"
] | permissive | use crate::loader::error::LoaderError;
use reqwest::blocking::Client;
use std::{fmt::Debug, sync::Arc, time::Duration};
use url::Url;
use crate::{
thread_safe_cache::ThreadSafeCacheTrait,
url_helpers::{parse_and_normalize_url, remove_fragment_from_url},
};
pub trait GetCache<T> {
fn get_cache(&self) -> &d... | true |
c74ba70a19e62827bdbc3402e3cf3f1a1279f78b | Rust | sgreenlay/aoc-2019 | /src/day23.rs | UTF-8 | 2,464 | 2.671875 | 3 | [] | no_license | use std::collections::HashSet;
use crate::intcode::{VirtualMachine, VirtualMachineState, load_program};
pub fn run() {
let program = load_program("data/day23.txt".to_string());
let mut template = VirtualMachine::new(&program);
match template.run() {
VirtualMachineState::WaitForInput => {}
... | true |
d6e10384f5e7435a7fe2dbd58f7aefec2e76cf83 | Rust | dB2510/rust_projects | /hello_world/main.rs | UTF-8 | 111 | 2.5625 | 3 | [] | no_license | fn main(){
println!("Hello, world!"); // ! means that you're calling a macro instead of a normal function
} | true |
60e81bb4e3a93e63caaf55935fdedc6913694fce | Rust | frankfanslc/L2 | /src/lib.rs | UTF-8 | 12,464 | 3.34375 | 3 | [
"MIT"
] | permissive | //! # L2
//!# What is L2?
//!
//!> L2 is named after the L2 or Euclidean distance, a popular distance function in deep learning
//!
//!L2 is a Pytorch-style Tensor+Autograd library written in the Rust programming language. It contains a multidimensional array class, `Tensor`, with support for strided arrays, numpy-styl... | true |
bdd2c3d4581c9b47ecc4eca6dbb4d37f33a0c88e | Rust | Lehona/Parsiphae | /src/parsers/statement/assignment.rs | UTF-8 | 2,235 | 2.96875 | 3 | [
"MIT"
] | permissive | use inner_errors::ParserError;
use parsers::{expression, var_access};
use types::{Assignment, AssignmentOperator, Input};
named!(pub assignment<Input, Assignment, ParserError>, fix_error!(ParserError, gws!(do_parse!(
lhs: var_access >> multispace0 >>
op: alt!(
tag_e!("+=")
| tag_e!("-=")
... | true |
d3a15e49ba149e5e9439fc11fd56a17e67af6752 | Rust | RobertZ2011/diesel | /src/lib/parser/expr/expr_value.rs | UTF-8 | 695 | 3.03125 | 3 | [
"MIT"
] | permissive | use super::Expr;
use super::{
BinOp,
UnaryOp
};
use std::fmt::{
Debug,
Formatter
};
#[derive(Clone, Debug)]
pub struct IfExpr<E: Expr> {
pub cond: Box<E>,
pub then_expr: Box<E>,
pub else_expr: Box<E>
}
/// Enum to represent all possibile expressions
/// Generic to support different expres... | true |
d6732d1deedfd0d9dc9bff1e85d8209db74ebf65 | Rust | jduan/cosmos | /rust_sandbox/rust_sandbox/src/modules.rs | UTF-8 | 2,272 | 3.15625 | 3 | [
"MIT"
] | permissive | // declare sub modules
mod nested;
mod privated_nested;
// Items in modules default to private visibility.
pub fn private_function() {
println!("called `modules::private_function()`");
}
// Use the `pub` modifier to override default visibility.
pub fn function() {
println!("called `modules::function()`");
}
... | true |
24b84652e4772292abb56c601e437a177eb59fd9 | Rust | subdir/pkb | /src/rank/quads.rs | UTF-8 | 1,347 | 3.109375 | 3 | [] | no_license | use std::fmt;
use sequential::{Sequential, LowBound};
use value::Value;
use rank::distinct::Distinct;
use rank::permutations_count;
#[derive(Debug)]
#[derive(Clone, Copy)]
#[derive(Eq, PartialEq, Ord, PartialOrd)]
pub struct Quads {
quads: Distinct<Value, Value>
}
impl Quads {
pub fn new(quads_value: Value... | true |
1d0c31a901edfec8cea13222ec9b7adba9687273 | Rust | delneg/bitcoin-address-generator-api | /jelly/src/jobs.rs | UTF-8 | 620 | 2.65625 | 3 | [
"MIT"
] | permissive | //! This module contains types used in Job registration and handling.
use sqlx::postgres::PgPool;
pub use background_jobs::{Job, WorkerConfig};
pub const DEFAULT_QUEUE: &'static str = "default";
/// This type can be used to indicate what environment a job is running in,
/// as well as gaining access to a database c... | true |
505ce54faf186ad23e7a75493feba0be6f0da537 | Rust | Jkillelea/projects | /rust/book/enums.rs | UTF-8 | 884 | 3.90625 | 4 | [] | no_license | /*
* An enum in Rust is a type that represents data that is one of several possible variants. Each variant
* in the enum can optionally have data associated with it:
*/
enum Message {
Quit,
ChangeColor(i32, i32, i32),
Move {x: i32, y: i32},
Write(String)
}
/*
* Enum values are scoped by their type.... | true |
277ccf64c846102459bd0c09b286c1768e7e737c | Rust | jimmyhmiller/PlayGround | /rust/rules2/src/main.rs | UTF-8 | 11,193 | 3.40625 | 3 | [] | no_license | #![feature(box_syntax, box_patterns)]
use core::fmt::Debug;
use std::collections::VecDeque;
use std::collections::HashMap;
#[derive(Debug, Clone)]
enum Term {
Literal(String),
Int(i64),
LogicVariable(String),
Pair(Box<Term>, Box<Term>),
Three(Box<Term>, Box<Term>, Box<Term>)
}
impl Into<Term> fo... | true |
e5d0c088d06b5458c914650cb88d2f35b9ed478b | Rust | jTitor/leek2 | /src/open-source/engine/modules/src/graphics/device/device.rs | UTF-8 | 528 | 3.03125 | 3 | [] | no_license | use std::fmt;
use super::BackendType;
/**
Represents a physical graphics device. This gets sent draw calls.
*/
pub trait Device {
/**
Returns the type of backend implementation
used by this device.
*/
fn backend_type(&self) -> BackendType;
/**
Performs any per-frame cleanup the device may need
to do.
*/
//Ma... | true |
68f0150812e82775044a9acedce61d72a76241a9 | Rust | gianlucamazza/proofmarshal | /proofmarshal-core/src/commit/impls/options.rs | UTF-8 | 877 | 3.1875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use super::*;
impl<T: Verbatim> Verbatim for Option<T> {
const LEN: usize = 1 + T::LEN;
fn encode_verbatim_in(&self, dst: &mut impl WriteVerbatim) {
match self {
None => dst.write_zeros(Self::LEN),
Some(value) => {
dst.write_bytes(&[1]);
dst.writ... | true |
770654ec6ab2c2fbc15202d79d331bc5d8cf3e99 | Rust | moevis/moevis-blog | /src/siteconfig.rs | UTF-8 | 1,116 | 2.890625 | 3 | [] | no_license | use config::Config;
use std::collections::HashMap;
use config::File;
lazy_static! {
pub static ref SITE_CONFIG: SiteConfig = {
let mut config = Config::default();
config.merge(File::with_name("site_config.yml")).unwrap();
let site_config = SiteConfig {
site_author: config.get(... | true |
15570641b3ad07e6551cebc523fb859d6576aa4b | Rust | gtsiam/env_logger | /examples/custom_target.rs | UTF-8 | 2,327 | 3.34375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | /*!
Using `env_logger`.
Before running this example, try setting the `MY_LOG_LEVEL` environment variable to `info`:
```no_run,shell
$ export MY_LOG_LEVEL='info'
```
Also try setting the `MY_LOG_STYLE` environment variable to `never` to disable colors
or `auto` to enable them:
```no_run,shell
$ export MY_LOG_STYLE=n... | true |
ea30e6b92248b91709b164ee65b91cfedef2755b | Rust | Sungmin-Joo/Algorithm-competition | /BAEK_JOON/Rust_algorithm/백준_1000번_A_plus_B/src/main.rs | UTF-8 | 429 | 3 | 3 | [] | no_license | use std::io;
fn main() {
let mut s = String::new();
io::stdin().read_line(&mut s)
.expect("error");
/*let a = s[..1].to_string();
let b = s[2..3].to_string();
let a: u32 = a.parse()
.expect("error");
let b: u32 = b.parse()
.expect("error");
println!("{}",a + b);... | true |
d253d2c1887cbb1488e9b7983ea108f8c19980c0 | Rust | willfindlay/rd | /src/taskish_uid.rs | UTF-8 | 4,393 | 2.890625 | 3 | [
"MIT",
"BSD-2-Clause"
] | permissive | use crate::{
session::{address_space::address_space::AddressSpace, task::Task},
thread_group::ThreadGroup,
};
use libc::pid_t;
use std::{
cmp::Ordering,
fmt,
hash::{Hash, Hasher},
marker::PhantomData,
ops::Deref,
};
/// Need to manually derive Hash, Copy, Clone, Eq, PartialEq, Ord, PartialO... | true |
88e62f2a659906987133a8c60dec210a8b7886d4 | Rust | itsananderson/advent-of-code-2020 | /rust/src/bin/09-solution2.rs | UTF-8 | 973 | 3.21875 | 3 | [
"MIT"
] | permissive | use std::env;
use std::fs;
use std::string::String;
use std::process::exit;
fn main() {
let args: Vec<String> = env::args().collect();
let filename = &args[1];
let target_sum = args[2].parse::<usize>().unwrap();
println!("Looking for ranges In file {} with sum {}", filename, target_sum);
... | true |
8dd4df5cd26c9cfdfdde599150b55ecb1ea9b147 | Rust | xcshuan/coding_interviews | /rust/coding_interviews/src/n04_find_in_2d_matrix.rs | UTF-8 | 1,260 | 3.359375 | 3 | [] | no_license | pub struct Solution;
#[allow(dead_code)]
impl Solution {
pub fn find_in_2d_matrix(
matrix: &Vec<Vec<i32>>,
columns: usize,
rows: usize,
number: i32,
) -> Result<bool, &'static str> {
if matrix.len() != rows {
return Err("Size unmatched!");
... | true |
4a11f34efc59c3bb6a0cc60104b9e4435d61a799 | Rust | nottxy/excel_column_id | /src/lib.rs | UTF-8 | 1,822 | 3.390625 | 3 | [
"MIT"
] | permissive | use std::{
cmp::Ordering,
hash::{Hash, Hasher},
};
#[cfg(feature = "with-serde")]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Eq)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub struct ColumnId {
id: usize,
name: String,
}
impl ColumnId {
pub fn id(&self) ... | true |
daaae33d709bcdd7a382cd5b8fcc6bc09a2cc522 | Rust | someguynamedmatt/js.rs | /src/lib/back/compiler.rs | UTF-8 | 6,278 | 2.90625 | 3 | [
"MIT"
] | permissive | use front::run::compiler::Compiler;
use syntax::ast::constant::*;
use syntax::ast::op::*;
use syntax::ast::expr::Expr;
use syntax::ast::constant::Const::*;
use syntax::ast::op::CompOp::*;
use jit::{
// Context,
Compile,
Function,
Value,
get_type,
SysBool,
Int,
UInt,
NInt,
NUInt,
... | true |
fbe5cfe826a6689c675e9c9a096feff50a2d47cb | Rust | qeeg/kind-nes | /nes/src/cartridge/mod.rs | UTF-8 | 3,844 | 2.828125 | 3 | [] | no_license | use memory::Memory;
use std::fs::File;
use std::io::prelude::*;
mod cartridge_metadata;
use cartridge_metadata::CartridgeMetadata;
pub use cartridge_metadata::Mirroring;
mod mapper;
use mapper::*;
pub struct Cartridge {
meta: Option<CartridgeMetadata>,
mapper: Option<Box<dyn Mapper>>,
}
impl Cartridge {
... | true |
d097ecf303206b30651ffc482fd4dc8340b452f4 | Rust | dgreid/adhd | /cras/client/cras_tests/src/arguments.rs | UTF-8 | 15,890 | 2.90625 | 3 | [
"BSD-1-Clause",
"BSD-3-Clause",
"LicenseRef-scancode-bsd-x11",
"LicenseRef-scancode-other-permissive"
] | permissive | // Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use std::error;
use std::fmt;
use std::path::PathBuf;
use audio_streams::SampleFormat;
use getopts::{self, Matches, Options};
#[derive(Debug)]
pub enu... | true |
5a46412fed4bde940bd78e263b269b2ce440bcc4 | Rust | vlmonk/advent2020 | /src/day16/main.rs | UTF-8 | 5,181 | 3.03125 | 3 | [] | no_license | use std::collections::{HashMap, HashSet};
use std::convert::TryFrom;
use std::error::Error;
use std::fs;
use lazy_static::lazy_static;
use regex::Regex;
#[derive(Debug)]
struct Range {
from: usize,
to: usize,
}
impl Range {
fn include(&self, input: usize) -> bool {
input >= self.from && input <= ... | true |
c825b909dfba940d112c2d41a2de844520e3bf1b | Rust | all-in-one-of/advent_of_code_2018 | /src/day14.rs | UTF-8 | 2,535 | 2.984375 | 3 | [
"Unlicense"
] | permissive | day!(
day14,
"https://adventofcode.com/2018/day/14/input",
part1,
part2
);
use twoway::find_bytes;
#[derive(Debug, Clone)]
struct State {
recipes: Vec<u8>,
cursor1: usize,
cursor2: usize,
}
impl State {
fn new() -> State {
State {
recipes: vec![3, 7],
c... | true |
58f12d708c5801243485039f0f49c6dfc8005b07 | Rust | bytebeamio/minirumqtt | /base/src/network.rs | UTF-8 | 5,327 | 2.890625 | 3 | [
"Apache-2.0"
] | permissive | use bytes::BytesMut;
use mqttbytes::*;
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use crate::{MqttState, StateError};
use std::io;
pub type Incoming = Packet;
/// Current outgoing activity on the eventloop
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum Outgoing {
/// Publish packet wit... | true |
34fc33f30dc0e85df53bbb956a1551de624dd3c9 | Rust | potatosalad/exercism | /rust/rna-transcription/src/lib.rs | UTF-8 | 2,113 | 3.328125 | 3 | [] | no_license | #[derive(Debug, PartialEq)]
pub struct DNA {
nucleotides: Vec<DNANucleotide>,
}
#[derive(Debug, PartialEq)]
pub struct RNA {
nucleotides: Vec<RNANucleotide>,
}
impl DNA {
pub fn new(dna: &str) -> Result<DNA, usize> {
let mut nucleotides = Vec::new();
for (i, c) in dna.chars().enumerate() {... | true |
ff894a915487d65dc764679b3b8d5c313acf141d | Rust | strengthen/LeetCode | /Rust/1.rs | UTF-8 | 765 | 2.8125 | 3 | [
"MIT"
] | permissive | __________________________________________________________________________________________________
//runtime: 0ms, memory: 2.5MB
impl Solution {
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
use std::collections::HashMap;
let mut hash = HashMap::new();
for i in 0..nums.len() {
... | true |
c2d003979de84890aff8770df16c01e3013c4be6 | Rust | ndenev/shio-rs | /lib/src/http.rs | UTF-8 | 2,468 | 2.65625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | //! Types that map directly to concepts in HTTP.
//!
//! This module exports types that map to HTTP concepts or to the underlying HTTP library
//! when needed.
#![allow(non_upper_case_globals)]
use hyper;
use http_types;
// NOTE: This facade is only around to not completely break current usage of 0.2.
// It wil... | true |
6cd42805ada12e957e87df03203e3e537823ebf0 | Rust | matthew-mcallister/playstation-emulator | /src/cpu/operations/nor.rs | UTF-8 | 1,152 | 3.375 | 3 | [] | no_license | use crate::cpu::delay::Delay;
use crate::cpu::exception::Exception;
use crate::cpu::interconnect::Interconnect;
use crate::cpu::operations::Operation;
use crate::cpu::registers::Registers;
use crate::instruction::Instruction;
/// Bitwise not or
///
/// nor $25, $2, $zero
/// It simply computes a bitwise OR between two... | true |
2bd69af36afd4bb8ff86a1e0487267c18da935af | Rust | matklad/fall | /fall/test/tests/arith.rs | UTF-8 | 2,893 | 2.890625 | 3 | [
"MIT"
] | permissive | extern crate fall_test;
extern crate fall_tree;
use fall_test::{arith, match_ast};
use fall_tree::dump_file;
fn ast(code: &str) -> String {
dump_file(&arith::language().parse(code.to_owned()))
}
#[test]
fn trivial() {
match_ast(&ast("1"), r#"
FILE
CONSTANT_EXPR
NUMBER "1"
"#);
}
#[test]
fn simple() {... | true |
86809ee19c81df9c35128f7ccb4f7a5fe2b906bf | Rust | thecoshman/http | /src/util/os/windows.rs | UTF-8 | 472 | 2.5625 | 3 | [
"MIT"
] | permissive | use winapi::um::fileapi::GetFileAttributesW;
use std::os::windows::ffi::OsStrExt;
use std::fs::Metadata;
use std::path::Path;
/// Get windows-style attributes for the specified file
///
/// https://docs.microsoft.com/en-gb/windows/win32/fileio/file-attribute-constants
pub fn win32_file_attributes(_: &Metadata, path: ... | true |
de7ba42d03830e074e6b6eeda088b9b740e490b3 | Rust | cfeitong/imageproc | /src/geo/types.rs | UTF-8 | 1,028 | 2.953125 | 3 | [
"MIT"
] | permissive | use std::fmt::Display;
use std::ops::{Neg, Mul, Div};
use std::cmp::{min, max};
use num::{Bounded, Num, NumCast};
pub trait NumMinMax {
fn min(self, other: Self) -> Self;
fn max(self, other: Self) -> Self;
}
pub trait GeoScalar: Copy + NumCast + Num
+ PartialOrd<Self> + Clone + Bounded
+ Display + Neg... | true |
b986b41e3b775a4dcf2390401661af4b4b270393 | Rust | swagger-api/swagger-codegen | /samples/server/petstore/rust-server/src/models.rs | UTF-8 | 25,888 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | #![allow(unused_imports, unused_qualifications, unused_extern_crates)]
extern crate chrono;
extern crate uuid;
use serde_xml_rs;
use serde::ser::Serializer;
use std::collections::HashMap;
use models;
use swagger;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AdditionalPropertiesClass {
#... | true |
b9e23e004deb179db798715d54bbe8cd2e079b6c | Rust | facebook/hermes | /unsupported/juno/crates/juno_ir/src/value_list.rs | UTF-8 | 8,562 | 2.9375 | 3 | [
"MIT"
] | permissive | /*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
use std::cell::Cell;
use std::cell::UnsafeCell;
use std::mem;
use std::mem::MaybeUninit;
use intrusive_collections::LinkedList;
... | true |
460a7f87a594dc4875ad40b66d4e7695d79de40e | Rust | nbari/policyd-rate-limit | /src/bin/policyd-rate-limit.rs | UTF-8 | 7,052 | 2.65625 | 3 | [
"BSD-3-Clause"
] | permissive | use clap::{App, Arg, SubCommand};
use policyd_rate_limit::queries;
use std::error::Error;
use std::io::Write;
use std::io::{BufRead, BufReader};
use std::os::unix::net::{UnixListener, UnixStream};
use std::process;
use std::thread;
#[derive(Debug, Default, Clone)]
pub struct CreateUser {
limit: Option<usize>,
... | true |
d4f2868955861b03c40deb9b08a12fe0773971e2 | Rust | p0lunin/lambda-calculator | /src/main.rs | UTF-8 | 767 | 3.09375 | 3 | [] | no_license | use lambda_calculator::Interpreter;
use clap::App;
use std::io;
use std::io::Write;
use std::convert::identity;
fn main() {
let app = App::new("Lambda-calculator")
.version("alpha")
.author("Dmytro Polunin")
.about("Tool for working with untyped lambda calculus");
let it = Interpreter::... | true |
cd871409593d91b5143586cdc55128514abd87e8 | Rust | joykhatter/poly-Rust | /polyrust.rs | UTF-8 | 441 | 3.25 | 3 | [] | no_license |
const size: usize= 10
struct Poly {
coeff: [f64;size],
degree: u32,
}
impl Poly {
fn eval ( &self , x: f64 ) -> f64
{
let mut ans = 0
let mut temp1 = 0
let mut temp2 = 0
for i in 0..self.degree
{
temp1 = x.powi(i)
temp2 = self.coeff[i] * temp1
ans = ans + temp1
}
} ... | true |
1b6ddbdc4a974a50f42b5bdb023682e42904d786 | Rust | hrvolapeter/servo | /scripts/script_thread.rs | UTF-8 | 1,848 | 2.546875 | 3 | [] | no_license | /* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//! The script thread is the thread that owns the DOM in memory, runs JavaScript, and spawns parsing
//! and layou... | true |
6b51deac10b9c09d060fe60070be8b6448d0690b | Rust | nham/vaughan | /src/mine.rs | UTF-8 | 1,998 | 3.1875 | 3 | [] | no_license | use dlist::DList;
use std::collections::Deque;
use tree::Tree;
mod tree;
mod dlist;
type StrTree<'a> = Tree<&'a str>;
type Doodad<'a> = DList<StrTree<'a>>;
#[deriving(PartialEq, Eq)]
struct Operator<'a> {
rep: &'a str,
}
impl<'a> Operator<'a> {
fn new<'a>(rep: &'a str) -> Operator<'a> {
Operator { ... | true |
f909e81c42ed089b40720c297872db2ee04d719e | Rust | johannessarpola/rs-hackernews-cli | /cli/src/formatting/tag_formatter.rs | UTF-8 | 4,761 | 3.5625 | 4 | [
"MIT"
] | permissive | use regex::Regex;
use super::formatter::FormatStr;
pub struct TagFormatter;
impl FormatStr for TagFormatter {
fn format(&self, s: &str) -> String {
let mut r = self.format_paragraphs(s);
// currently no special formatting for links so just format like other tags (remove)
r = self.format_co... | true |
1a41a258ae0fada27e98cd617d309985dce37072 | Rust | sidred/collenchyma | /src/framework.rs | UTF-8 | 4,085 | 3.453125 | 3 | [
"MIT"
] | permissive | //! Provides the generic functionality of a hardware supporting frameworks such as native CPU, OpenCL,
//! CUDA, etc..
//! [hardware]: ../hardware/index.html
//!
//! The default Framework would be plain host CPU for common computation. To make use of other
//! computation hardwares such as GPUs you would choose other c... | true |
ed8e8ca16771f0f2a45d8b64547a111d36ac6e77 | Rust | N-give/codesignal | /first-non-repeating/src/main.rs | UTF-8 | 593 | 3.421875 | 3 | [] | no_license | use std::collections::HashMap;
fn main() {
println!("{}", firstNotRepeatingCharacter(String::from("abacbad")));
}
fn firstNotRepeatingCharacter(s: String) -> char {
let mut seen: HashMap<char, (usize, usize)> = HashMap::new();
s.char_indices().for_each(|(i, c)| {
let cnt = seen.entry(c).or_insert(... | true |
42124ad80282ac499ae7f6c307634d6c56d54739 | Rust | KoSasha/Compiler | /src/main/resources/examples/min.rs | UTF-8 | 303 | 3.515625 | 4 | [] | no_license | fn main() {
let array = [1, 2, 77, -34, -35, 9];
let min: i32 = min(array);
println!("{}", min);
}
fn min(array: [i32;6]) -> i32 {
let mut min: i32 = array[0b0];
for index in 1..6 {
if min > array[index] {
min = array[index];
}
}
return min;
}
.
| true |
a40bbc993e5f364b4008dab337d6aaae326b815f | Rust | yuv418/multihangman | /udpclient/src/connect.rs | UTF-8 | 9,181 | 2.53125 | 3 | [] | no_license | use std::collections::HashMap;
use crate::hangmanclient::HangmanClient;
use std::sync::Arc;
use crate::opening::OpeningScene;
use raylib::prelude::*;
use crate::raylibscene::RaylibScene;
use crate::resources::Resources;
use crate::textbox::TextBox;
use raylib::ease::*;
use std::thread;
use std::time::Duration;
use crat... | true |
8852ff405a4ab7a8115364e78113740b7287789b | Rust | czyczk/LeetCode | /rust/lc-684/src/main.rs | UTF-8 | 379 | 2.609375 | 3 | [] | no_license | mod solution;
use solution::Solution;
fn main() {
let edges1 = vec![vec![1, 2], vec![1, 3], vec![2, 3]];
let edges2 = vec![vec![1, 2], vec![2, 3], vec![3, 4], vec![1, 4], vec![1, 5]];
// Expecting [2, 3]
println!("{:?}", Solution::find_redundant_connection(edges1));
// Expecting [1, 4]
printl... | true |
6623a49cb08fc9dce86c36d67f35bc6d4077ddcd | Rust | rileysu/ps2emu | /src/emotion_engine/memory.rs | UTF-8 | 5,567 | 2.65625 | 3 | [] | no_license | pub const KiB: usize = 1024;
pub const MiB: usize = 1024 * KiB;
pub type Address = usize;
enum AddressLocation {
MainEEMemory(Address),
IORegisters(Address),
VU0CodeMemory(Address),
VU0DataMemory(Address),
VU1CodeMemory(Address),
VU1DataMemory(Address),
GSPrivilegedRegisters(Address),
... | true |
8571e9334dab2b5a3db6ad94aee627cf89875003 | Rust | mpdn/inertial-flow | /src/dinic.rs | UTF-8 | 12,807 | 2.671875 | 3 | [
"MIT"
] | permissive | use fixedbitset::FixedBitSet;
use petgraph::csr::{Csr, EdgeReference, Edges};
use petgraph::graph::IndexType;
use petgraph::visit::{EdgeRef, IntoNeighbors};
use petgraph::EdgeType;
use std::collections::HashSet;
use std::hash::BuildHasher;
use std::hash::Hash;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOr... | true |
e96963d51edb640f2b40db4270cc990bdbeedc63 | Rust | tomcumming/geometric-algebra | /symbolic-ga/src/element.rs | UTF-8 | 5,599 | 3.171875 | 3 | [] | no_license | use std::cmp::Ordering;
use std::collections::BTreeSet;
use crate::basis::{Basis, SquaredElement, Vector};
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord)]
pub struct Element(pub BTreeSet<Vector>);
#[derive(Debug, Clone, PartialEq)]
pub enum SimplifiedElement {
Zero,
Positive(Element),
Negative(El... | true |
4dcbf488557ee031fcc9bfdb67fe934bfe356a37 | Rust | dfoxfranke/metrics | /metrics-util/benches/streaming_integers.rs | UTF-8 | 3,660 | 2.796875 | 3 | [
"MIT"
] | permissive | #[macro_use]
extern crate criterion;
#[macro_use]
extern crate lazy_static;
use criterion::{Benchmark, Criterion, Throughput};
use metrics_util::StreamingIntegers;
use rand::{
distributions::{Distribution, Gamma},
rngs::SmallRng,
Rng, SeedableRng,
};
use std::time::Duration;
lazy_static! {
static ref... | true |
a7ef9ba0a17e4370a968c91b4c87eb3f3dd732e4 | Rust | frankegoesdown/LeetCode-in-Go | /Algorithms/0832.flipping-an-image/flipping-an-image.go | UTF-8 | 399 | 2.84375 | 3 | [
"MIT"
] | permissive | package problem0832
func flipAndInvertImage(A [][]int) [][]int {
for k := 0; k < len(A); k++ {
i, j := 0, len(A[k])-1
for i < j {
A[k][i], A[k][j] = invert(A[k][j]), invert(A[k][i])
i++
j--
}
if i == j { // 当 len(A[k]) 的长度为奇数时,处理正中间的数
A[k][i] = invert(A[k][i])
}
}
return A
}
func invert(i int... | true |
1415ff8d5f654b048a12a6f1b5a9efba1188a42a | Rust | Warhorst/telegram_bot_api_parser | /src/code_generator/renderer.rs | UTF-8 | 10,439 | 2.796875 | 3 | [] | no_license | use handlebars::{Handlebars, TemplateError, TemplateFileError, RenderError};
use serde::Serialize;
use crate::code_generator::configuration::{Configuration, Rename, TemplateFile};
use crate::code_generator::target_files::TargetFile;
use crate::raw_api::type_descriptor::TypeDescriptor;
use crate::code_generator::names:... | true |
50a38f753e0bc1311b3be4a5cffd28ee6e4ad49e | Rust | bouzuya/rust-atcoder | /cargo-atcoder/contests/agc034/src/bin/a.rs | UTF-8 | 1,100 | 2.796875 | 3 | [] | no_license | use proconio::input;
use proconio::marker::{Chars, Usize1};
fn main() {
input! {
_: usize,
a: Usize1,
b: Usize1,
c: Usize1,
d: Usize1,
s: Chars,
};
if c < d {
let mut is_ok = true;
for i in a + 1..=c {
if s[i - 1] == '#' && s[i] ==... | true |
04216fe71f7f7023020792e726fe5c6f9caad6e5 | Rust | DrGabble/hypergraph | /src/core/shared.rs | UTF-8 | 2,187 | 2.671875 | 3 | [
"MIT"
] | permissive | use crate::{Hypergraph, SharedTrait, VertexIndex};
use itertools::Itertools;
impl<V, HE> Hypergraph<V, HE>
where
V: SharedTrait,
HE: SharedTrait,
{
/// Private helper function used internally.
pub(crate) fn get_connections(
&self,
from: VertexIndex,
to: Option<VertexIndex>,
... | true |
12794de89e3120dd31dc4daa0ed7c5590bddb279 | Rust | Trolldemorted/rpfm | /src/settings/mod.rs | UTF-8 | 9,560 | 2.921875 | 3 | [
"MIT"
] | permissive | // In this module should be everything related to the settings stuff.
extern crate serde_json;
extern crate failure;
use std::path::PathBuf;
use std::fs::File;
use std::io::Write;
use std::io::BufReader;
use failure::Error;
/// `GameInfo`: This struct holds all the info needed for a game to be "supported" by RPFM fe... | true |
1468eb365585042e2875e92d668da84f47aa0ab3 | Rust | SamHDev/tycho | /src/read/async_/length.rs | UTF-8 | 493 | 2.59375 | 3 | [
"MIT"
] | permissive | use tokio::io::AsyncRead;
use crate::error::TychoResult;
use crate::read::async_::func::read_byte_async;
pub(crate) async fn read_length_async<R: AsyncRead + Unpin>(reader: &mut R) -> TychoResult<usize> {
let mut number: u64 = 0;
let mut count = 0_i32;
loop {
let byte = read_byte_async(reader).aw... | true |
8ebbf4f33e71964760d4891b5fd6f1bf6fb46ed0 | Rust | m9s/xmc1000 | /xmc1000/src/scu_clk/osccsr/mod.rs | UTF-8 | 11,285 | 2.84375 | 3 | [] | no_license | #[doc = r" Value read from the register"]
pub struct R {
bits: u32,
}
#[doc = r" Value to write to the register"]
pub struct W {
bits: u32,
}
impl super::OSCCSR {
#[doc = r" Modifies the contents of the register"]
#[inline]
pub fn modify<F>(&self, f: F)
where
for<'w> F: FnOnce(&R, &'w mu... | true |
0e26a131c80bf055a5e381086a31c6828004c23d | Rust | MalteT/console-hero | /src/data/card/helper.rs | UTF-8 | 7,830 | 3.5625 | 4 | [
"MIT"
] | permissive | use pad::PadStr;
use regex::Regex;
use textwrap::wrap_iter;
use unicode_width::UnicodeWidthStr as UW;
/// Calculate the width of a string containing escape codes for coloring.
pub fn terminal_string_width(s: &str) -> usize {
let re = Regex::new(r"\x1B\[.*?m").unwrap();
re.replace_all(s, "").width()
}
/// Wrap... | true |
cc0cd4566ad85e219bcc40c6303e30a3190840d1 | Rust | RavuAlHemio/md-context | /src/texutil.rs | UTF-8 | 8,701 | 3.078125 | 3 | [
"MIT"
] | permissive | use lazy_static::lazy_static;
use regex::{Captures, Regex};
use crate::md_ast::{MarkdownElement, MarkdownFormat, MarkdownFragment};
lazy_static! {
static ref EDUCATED_QUOTE_RE: Regex = Regex::new("(?m)(^|.)\"").unwrap();
}
pub fn escape_tex(text: &str) -> String {
let mut ret = String::with_capacity(text.l... | true |
a6105b677041649fb831c0d0d38ad6d459c5e2c5 | Rust | Garvys/rustfst | /rustfst/src/fst_traits/serializable_fst.rs | UTF-8 | 6,648 | 2.640625 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::fs::File;
use std::io::{BufWriter, LineWriter, Write};
use std::path::Path;
use anyhow::{Context, Result};
use unsafe_unwrap::UnsafeUnwrap;
use crate::fst_traits::ExpandedFst;
use crate::parsers::text_fst::ParsedTextFst;
use crate::semirings::SerializableSemiring;
use crate::Trs;
use crate::{DrawingConfig, S... | true |
69a5518dd44abf11afbeeb04165d84b21453271d | Rust | astral-sh/ruff | /crates/ruff_python_formatter/tests/fixtures.rs | UTF-8 | 9,139 | 2.515625 | 3 | [
"BSD-3-Clause",
"0BSD",
"LicenseRef-scancode-free-unknown",
"GPL-1.0-or-later",
"MIT",
"Apache-2.0"
] | permissive | use ruff_formatter::FormatOptions;
use ruff_python_formatter::{format_module, PyFormatOptions};
use similar::TextDiff;
use std::fmt::{Formatter, Write};
use std::io::BufReader;
use std::path::Path;
use std::{fmt, fs};
#[test]
fn black_compatibility() {
let test_file = |input_path: &Path| {
let content = fs... | true |
fb2e0637388aa73093e3756977da460e75549f36 | Rust | fafk/tx_processor | /tests/integration_tests.rs | UTF-8 | 869 | 2.734375 | 3 | [] | no_license | use assert_cmd::prelude::*;
use std::process::Command;
#[test]
pub fn invalid_args() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("tx_processor")?;
cmd.arg("foobar").arg("test/file/doesnt/exist");
cmd.assert()
.failure();
Ok(())
}
#[test]
pub fn correct_start() ... | true |
1954fdf4a035859fdfee6ecc1171118d9cb845bd | Rust | cch123/test | /rust/proc_macro_workshop/src/bool_expr.rs | UTF-8 | 615 | 2.71875 | 3 | [] | no_license | /*
follow 规则:
item: anything.
block: anything.
stmt: => , ;
pat: => , = if in
expr: => , ;
ty: , => : = > ; as
ident: anything.
path: , => : = > ; as
meta: anything.
tt: anything.
*/
#[macro_export]
macro_rules! and_expr {
() => {
false
};
($left:expr ; and $right:expr) => {
if $left && $ri... | true |
e30ffdd4a3473f5968f48304c8ab2af1a64bb0d4 | Rust | rail44/programming-bitcoin | /src/helper.rs | UTF-8 | 2,934 | 2.921875 | 3 | [
"Unlicense"
] | permissive | use digest::Digest;
use num_bigint::{BigInt, Sign};
use num_traits::ToPrimitive;
use ripemd160::Ripemd160;
use sha2::Sha256;
use std::io::Read;
static BASE58_ALPHABET: &str = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
pub fn encode_base58(bytes: &[u8]) -> String {
let mut count = 0;
for b i... | true |
1384ba5799fa300896d3170cf207c3982b8e823a | Rust | k0pernicus/aoc2020 | /ex08/src/main.rs | UTF-8 | 1,610 | 2.6875 | 3 | [] | no_license | #[macro_use]
extern crate aoc_helper;
use aoc_helper::commandline::AOCApp;
use aoc_helper::file;
use std::process;
mod lib;
use lib::{parser, vm};
fn main() {
let args = get_app_args!();
let input_filename = args.get_input_filename();
let input_content = file::get_content::<String>(input_filename.unwrap... | true |
81956eb82e23c48461c8b494830c6c64aff3942b | Rust | Azure/azure-sdk-for-rust | /services/mgmt/customerlockbox/src/package_2018_02_28_preview/models.rs | UTF-8 | 15,471 | 2.828125 | 3 | [
"LicenseRef-scancode-generic-cla",
"MIT",
"LGPL-2.1-or-later"
] | permissive | #![allow(non_camel_case_types)]
#![allow(unused_imports)]
use serde::de::{value, Deserializer, IntoDeserializer};
use serde::{Deserialize, Serialize, Serializer};
use std::str::FromStr;
#[doc = "Request content object, in the use of Approve or Deny a Lockbox request."]
#[derive(Clone, Debug, PartialEq, Serialize, Deser... | true |
4403508006e21fb53abad015988ebdc3e3c575f3 | Rust | bgeorges/rouille | /safecast-lib/src/lib.rs | UTF-8 | 864 | 3 | 3 | [] | no_license | pub mod models;
#[cfg(test)]
mod test {
use crate::models::Measurement;
use crate::models::User;
use std::fs;
#[test]
fn user_test() {
let joe = User {
id: 1,
name: String::from("Joe"),
measurements_count: None,
};
let bob = User {
... | true |
81656f5ae4cdbf1a1315d49ffd9cdd78b292e919 | Rust | fbriden/market-finance-rs | /src/indicators/traits.rs | UTF-8 | 721 | 3.125 | 3 | [
"MIT"
] | permissive | pub trait TechnicalIndicator {
type Output;
/// Gets the current indicator value.
fn current(self) -> Self::Output;
}
pub trait UpdatableIndicator<Input> {
type Output;
/// 'Commits' the current indicator value by copying it to the previous
/// value
///
/// This is used for historical calcul... | true |
af2d168618601249fff8b67de197f8083ea5ea92 | Rust | maekesw/Tutorial-Rust | /Assignment2.rs | UTF-8 | 2,028 | 3.75 | 4 | [] | no_license | use std::io;
fn main()
{
let mut letter = String::new();
let mut operator = String::new();
let mut number1 = String::new();
let mut number2 = String::new();
let result:i32;
let mut percentage = String::new();
let gradeuate;
println!("Question 1: Proof if Alphabet is vowel or not");
println!("Please enter... | true |
5604e0f0bd985db74b4a59d3bb83feafa2296cfd | Rust | masonium/liniya | /src/util.rs | UTF-8 | 1,417 | 3.28125 | 3 | [
"MIT"
] | permissive | use crate::common::*;
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum BoxPlaneTest {
Inside,
Intersects,
Outside,
}
/// Return the position of the bounding box relative to `bb`. The
/// bounding box is `Inside` if it is completely on the side facing
/// the normal.
///
/// # Remarks
///
/// Assumes... | true |
7c3a6115d593f575ebd16871a3cbbf635d742c0f | Rust | svmk/fund-watch-bot | /src/event_emitter/model/event_category.rs | UTF-8 | 269 | 2.65625 | 3 | [] | no_license | use std::any::TypeId;
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct EventCategory {
type_id: TypeId,
}
impl EventCategory {
pub fn from_type_id(type_id: TypeId) -> EventCategory {
return EventCategory {
type_id,
}
}
} | true |
3319631c7f2bdb26e8aad0dd691279c7d938372d | Rust | dnnr/advent-of-code-2020 | /src/day03.rs | UTF-8 | 1,290 | 3.828125 | 4 | [] | no_license | pub fn part1(inp: String) {
let slope = input_to_slope(inp);
let trees = count_trees(&slope, 3, 1);
println!("Trees: {}", trees);
}
pub fn part2(inp: String) {
let slope = input_to_slope(inp);
let movements = vec![(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)];
let trees: usize = movements
.... | true |
a2e8e1c708818db3148d70107b7f0cbfe0b2f1b7 | Rust | tesseract-olap/tesseract | /tesseract-clickhouse/src/sql/rca.rs | UTF-8 | 10,245 | 2.84375 | 3 | [
"MIT"
] | permissive | // Optimization for RCA
// Ordinarily, just a, b, c, and d are scanned separately and then combined by joins.
// a: (each product, each city) // can be cut on drill 1
// b: (all products, each city)
// c: (each product, all cities) // can be cut on drill 1
// d: (all products, all cities)
//
// Note that external cuts ... | true |
57a817ae17d877238b3156911f8d3aa5ab26333d | Rust | tiffany352/wasm-rs | /src/reader/bytecode.rs | UTF-8 | 15,079 | 2.796875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use super::*;
use std::io::Read;
use byteorder::{LittleEndian, ReadBytesExt};
pub struct OpIterator<'a> {
pub iter: &'a [u8],
nesting: usize
}
#[derive(Debug, Clone)]
pub struct BrTable<'a> {
pub count: u32,
raw: &'a [u8],
pub default: u32,
}
#[derive(Debug, Clone)]
pub struct BrTableArmIterator<... | true |
40b1cbb81420dea19f90d372cf4ef4508e7a04a2 | Rust | mozilla/gecko-dev | /third_party/rust/wast/src/encode.rs | UTF-8 | 1,654 | 2.796875 | 3 | [
"LLVM-exception",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | pub(crate) trait Encode {
fn encode(&self, e: &mut Vec<u8>);
}
impl<T: Encode + ?Sized> Encode for &'_ T {
fn encode(&self, e: &mut Vec<u8>) {
T::encode(self, e)
}
}
impl<T: Encode + ?Sized> Encode for Box<T> {
fn encode(&self, e: &mut Vec<u8>) {
T::encode(self, e)
}
}
impl<T: Enc... | true |
7a58aeb3ff465b617cf51554bfcb089ab25c7bc6 | Rust | Ynstc/vertigo | /crates/vertigo/src/computed/dependencies/graph.rs | UTF-8 | 4,682 | 2.640625 | 3 | [] | no_license | use std::collections::{BTreeMap, BTreeSet};
use crate::computed::graph_id::GraphId;
use super::{
external_connections::ExternalConnections,
graph_map::GraphMap
};
pub struct Graph {
parent_childs: GraphMap, //ParentId <- ClientId
client_parents: GraphMap, ... | true |
4cc6a8af149487f4671f6f7167a951b614663710 | Rust | nklizhe/aoc2020 | /src/day3.rs | UTF-8 | 1,823 | 3.21875 | 3 | [] | no_license | use super::utils;
fn day3_calc(map: &Vec<String>, right: usize, down: usize) -> usize {
let mut cnt: usize = 0;
let mut n: usize = 0;
for i in (0..map.len()).step_by(down) {
if i == 0 {
continue;
}
n = n + 1;
let row: &String = &map[i];
let p: usize = n *... | true |
f80a431c14bd4cfbf48d4950565b7d8842c664ff | Rust | hikilaka/rust_opengl | /src/scene/model.rs | UTF-8 | 1,984 | 2.625 | 3 | [] | no_license | use crate::glsl::Program;
use crate::rsgl::Bindable;
use crate::scene::{Camera, Mesh};
use gl::types::GLsizei;
use nalgebra::{Isometry3, Rotation3, Translation3, UnitQuaternion, Vector3};
pub enum RotationAxis {
X,
Y,
Z,
}
impl RotationAxis {
pub fn value(&self) -> Vector3<f32> {
match &self ... | true |
38648adc004653b20714c1d67dc35c0a008f49d1 | Rust | provable-things/ptokens-core | /src/chains/evm/core_initialization/check_eth_core_is_initialized.rs | UTF-8 | 907 | 2.671875 | 3 | [] | no_license | use crate::{chains::evm::eth_database_utils::get_public_eth_address_from_db, traits::DatabaseInterface};
pub fn is_eth_core_initialized<D: DatabaseInterface>(db: &D) -> bool {
get_public_eth_address_from_db(db).is_ok()
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{
chains::evm::{eth_databas... | true |
975004391d73a338fed5173bfd84028a06723684 | Rust | JulianKnodt/mireba | /src/camera/mod.rs | UTF-8 | 1,378 | 3.078125 | 3 | [] | no_license | pub mod builder;
pub mod orthographic;
pub mod perspective;
pub mod projective;
use crate::{film::Film, sampler::Samplers};
use quick_maths::{Ray3, Transform4, Vec2};
use std::fmt::Debug;
pub trait Camera: Debug {
/// Sample a ray from the camera using the given uv in [0,1]^2.
fn sample_ray(&self, sample_pos: Vec... | true |
b77871bbfc82cf76fdd5e55cfa619bb39ade7331 | Rust | Happy-Ferret/rdm | /rdm/src/ipc.rs | UTF-8 | 3,404 | 2.8125 | 3 | [
"MIT",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | use std::io::{self, Read, Write};
use std::net::{Shutdown};
use std::os::unix::io::{AsRawFd, FromRawFd};
use std::os::unix::net::{UnixListener, UnixStream};
use std::str;
use std::sync::Arc;
use std::thread;
use rdmcommon::ipc;
use futures::future::{self, Future, BoxFuture};
use tokio_core::reactor::Handle;
use tokio... | true |
ce0a1b8bf047535c980f84fe848a4a8e32951270 | Rust | BrantleighBunting/ExpressionIdentityVerifier | /src/domain/mod.rs | UTF-8 | 468 | 3.359375 | 3 | [
"MIT"
] | permissive | use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Domain {
Strings,
Algebra,
Sets,
Boolean
}
impl fmt::Display for Domain {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match self {
Domain::Strings => { write!(formatter, "Strings") }
Domain::Algebra => {writ... | true |
836b2e086bc81172415268e2b2948ee1e6d460af | Rust | rwebler/rust-dungeoncrawl | /src/map_builder/automata.rs | UTF-8 | 2,976 | 2.921875 | 3 | [] | no_license | use crate::prelude::*;
use super::MapArchitect;
pub struct CellularAutomataArchitect {}
impl CellularAutomataArchitect {
fn random_noise_map(
&mut self,
rng: &mut RandomNumberGenerator,
map: &mut Map
) {
map.tiles.iter_mut().for_each(|t| {
let roll = rng.range(0, 100... | true |
ecccb70adb72caf02621a022cfe373c44684d9fc | Rust | Aelto/games-package-manager | /src/prompt.rs | UTF-8 | 462 | 3.296875 | 3 | [] | no_license | use std::io::{self, Write};
pub fn prompt() -> Option<String> {
let mut answer = String::new();
match io::stdin().read_line(&mut answer) {
Ok(0) => None,
Ok(_) => Some(answer),
Err(err) => {
println!("error: {}", err);
None
}
}
}
pub fn prompt_with_question(question: &str) -> Optio... | true |
584177b8fb34930512c8a48aec559b84113afe91 | Rust | evaporei/stratosphere | /src/mode.rs | UTF-8 | 6,190 | 3.296875 | 3 | [] | no_license | use crate::number::Number;
use std::collections::HashMap;
#[derive(Debug, PartialEq)]
pub enum Mode<T> {
None,
Unimodal(T),
Bimodal(T, T),
Trimodal(T, T, T),
Multimodal(Vec<T>),
}
use std::str::FromStr;
use std::string::ToString;
pub fn mode<T: Number + ToString + FromStr>(data: &[T]) -> Mode<T> ... | true |
7e6ce6ae6b53e2683c1baacb67510d0bfa6c23f8 | Rust | NorabX/rustils | /tests/parse/short_impl.rs | UTF-8 | 4,727 | 2.75 | 3 | [
"MIT"
] | permissive | extern crate rustils;
use rustils::parse::short::*;
use rustils::RoundingMode::*;
use std::f32;
use std::f64;
#[test]
pub fn parse_bool_to_i16() {
let t = true;
let f = false;
assert_eq!(Ok(1), t.to_i16_res());
assert_eq!(Ok(0), f.to_i16_res());
assert_eq!(1, t.to_i16());
assert_eq!(0, f.to_... | true |
f1e3ef8bb4d14a2ae9e0d4be2365e77134d9b5e2 | Rust | fspmarshall/tokio-util | /src/service.rs | UTF-8 | 5,481 | 3.578125 | 4 | [] | no_license | //! Spawn simple cross-task services.
//!
//! Use the `spawn` function to launch a service into the tokio event-loop, returning
//! a cloneable handle.
//!
//! ## Example
//!
//! Use `spawn` and a `HashMap` to create a shared key-value store, with `Get`, `Set`
//! and `Del` operations modeled by an enum:
//!
//! ```
//... | true |
b877a594b9fcadfc9d072f541857f2d3256e6e90 | Rust | ldemouy/system_admin | /src/bin/system_admin_server_connection_plaintext/src/main.rs | UTF-8 | 1,254 | 2.8125 | 3 | [
"BSD-2-Clause"
] | permissive | use std::os::unix::net::UnixStream;
use std::io;
use std::io::prelude::*;
use std::net::Shutdown;
use system_admin_lib::messages::*;
use bincode::serialize;
use bincode::deserialize;
fn main() {
loop {
let mut socket = UnixStream::connect("/tmp/system_admin_server.socket").expect("unable to connect");
... | true |
72da72c0df9c5d1919bc887ac8fb709d6c2200f9 | Rust | mrobakowski/alcubierre | /alcubierre-derive/src/lib.rs | UTF-8 | 2,524 | 2.625 | 3 | [] | no_license | //#![feature(proc_macro_diagnostic)]
extern crate proc_macro;
use proc_macro::TokenStream;
use syn::*;
use syn::spanned::Spanned;
use quote::quote;
#[derive(Debug)]
struct Args {
path: Option<LitStr>,
}
impl parse::Parse for Args {
fn parse(input: &parse::ParseBuffer) -> syn::Result<Self> {
if inpu... | true |
41a3006104075b6ff9ed68f4feab1b163ecf1f30 | Rust | TonalidadeHidrica/taiko-wiki-data-analysis | /src/pukiwiki_parser/preprocess.rs | UTF-8 | 686 | 3.5 | 4 | [
"MIT"
] | permissive | /// - This string does not contain `\n`.
/// - In this string, newline is represented by `\r`.
/// - It ends with `\r`.
#[derive(Default)]
pub struct PreprocessedString(String);
impl FromIterator<char> for PreprocessedString {
fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self {
let mapper = |c| ma... | true |
83a9a4cc50464d7f3e771a737aaea19376e02a91 | Rust | idubrov/tuple-keys | /src/lib.rs | UTF-8 | 450 | 2.890625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | mod arity2;
mod arity3;
pub use arity2::*;
pub use arity3::*;
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use crate::{OwnedKey2, owned_key2, lookup_key2};
#[test]
fn test_arity2() {
let mut map: HashMap<OwnedKey2<String, String>, String> = HashMap::new();
map.insert(owned_... | true |
f52e2047b56603bf929cd05db265f431965485f4 | Rust | yeliknewo/ai-4x-rs | /src/art/main.rs | UTF-8 | 11,286 | 2.5625 | 3 | [] | no_license | use art::{Name, Size, Tint};
pub const NAME: Name = "main.png";
pub const SIZE: Size = &[410.0, 304.0];
pub const DEFAULT_TINT: Tint = &[0.5, 0.5, 0.5, 1.0];
pub mod yellow {
use art::Sprite;
const X_OFFSET: f32 = 4.0;
const Y_OFFSET: f32 = 4.0;
pub const ARRAY: &[Sprite; 6] = &[BLANK, X, CIRCLE, SQ... | true |
7c0155e604bb6c3b0e060fab7ec5c88d55944d55 | Rust | waffle-iron/mimir-1 | /src/common/error.rs | UTF-8 | 4,059 | 2.640625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | // Copyright (c) 2017 oic developers
//
// 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. All files in the project carrying such notice may not be copied,
// mo... | true |
de23039ff05aad6f2de0afc517dcfbe93261789b | Rust | zhylmzr/tex_tool | /src/main.rs | UTF-8 | 7,177 | 2.71875 | 3 | [] | no_license | mod texture;
use futures::{stream, Stream, StreamExt};
use image::{ImageBuffer, Rgba, RgbaImage};
use squish::Format::{Bc1, Bc3};
use std::{collections::VecDeque, convert::TryInto, io::Result, mem::transmute, path::PathBuf};
use tokio::{
fs::{read_dir, DirEntry, File},
io::AsyncReadExt,
};
use texture::*;
fn... | true |
f340cd1a95aba8ea17e9dab5a9cdf6e80c2fe8e3 | Rust | timvermeulen/advent-of-code | /src/solutions/year2016/day24.rs | UTF-8 | 1,943 | 2.921875 | 3 | [] | no_license | use super::*;
pub fn solve(input: &str) -> (u32, u32) {
let mut path = HashSet::new();
let mut numbers = [(0, 0); 8];
let mut map = HashMap::new();
for (y, line) in input.lines().enumerate() {
for (x, &c) in line.as_bytes().iter().enumerate() {
if c == b'#' {
contin... | true |
72812314b3fd4900cf116969b45f2e0f6e660a29 | Rust | shubhamkumar13/mincaml | /src/cg_types.rs | UTF-8 | 600 | 3.015625 | 3 | [] | no_license | use std::fmt;
use crate::type_check::Type;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RepType {
Word,
Float,
}
impl fmt::Display for RepType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RepType::Word => "W".fmt(f),
RepType::Float => ... | true |
87416f4d4527168876b6adf24cc1dc18275d376b | Rust | DTomusk/Rust-Exercises | /closures/src/main.rs | UTF-8 | 2,741 | 3.921875 | 4 | [] | no_license | // a closure stores a function in a variable
// the parameters are held in pipes (||) and then the function definition is given
// the variable assigned to it doesn't hold the result but the function itself
// closures aren't exposed to other users so you don't have to annotate parameter or return types
// closures are... | true |
1d9d38442854942b3f896e8483af63d88355dd81 | Rust | dylanmckay/lit | /src/event_handler/default.rs | UTF-8 | 9,302 | 2.71875 | 3 | [
"MIT"
] | permissive | use crate::{util, Config, model::*};
use itertools::Itertools;
use std::io;
use std::io::prelude::*;
use term;
/// The default event handler, logging to stdout/stderr.
pub struct EventHandler {
test_results: Vec<TestResult>,
}
impl EventHandler {
/// Creates a new default event handler.
pub fn new() -> S... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.