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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
dcbdab43df5a758a7938d619d20850f255cb66c3 | Rust | isgasho/baby-ftp | /src/ftp.rs | UTF-8 | 4,931 | 2.8125 | 3 | [] | no_license | use std::net::{TcpStream, ToSocketAddrs};
use std::io::{self, Write, BufReader, BufRead};
use std::time::Duration;
use regex::Regex;
use net2::TcpBuilder;
pub fn connect(mut _info: &mut ConnectionInfo, mut _client: &mut ClientInfo) -> bool {
let _status = conn_tcp_stream(&mut _client);
let mut _stream = TcpBui... | true |
cc25c8ac17da30bb6875a4e98308b5da34ad0604 | Rust | euclidr/leetcode | /examples/p386.rs | UTF-8 | 708 | 3.453125 | 3 | [] | no_license | struct Solution;
impl Solution {
pub fn lexical_order(n: i32) -> Vec<i32> {
let mut result = vec![];
for i in 1..10 {
if i > n {
break
}
result.push(i);
Solution::lexical_order2(&mut result, i*10, n);
}
result
}
... | true |
c140a73ffdc6b70d55c21262ebb81a96275158f8 | Rust | xsnippet/xsnippet-api | /src/web/auth/jwt.rs | UTF-8 | 12,108 | 2.953125 | 3 | [
"MIT"
] | permissive | use jsonwebtoken::{Algorithm, Validation};
use serde::{Deserialize, Serialize};
use super::{AuthValidator, Error, Permission, Result, User};
use crate::application::Config;
const SUPPORTED_ALGORITHMS: [Algorithm; 3] = [Algorithm::RS256, Algorithm::RS384, Algorithm::RS512];
/// JSON Web Key. A cryptographic key used ... | true |
159a7fe6b1736fa49fe9d16a306b985bd9abd1df | Rust | akberg/svlint | /src/rules/wire_reg.rs | UTF-8 | 945 | 2.8125 | 3 | [
"MIT"
] | permissive | use crate::linter::{Rule, RuleResult};
use sv_parser::{IntegerVectorType, NetType, NodeEvent, RefNode, SyntaxTree};
#[derive(Default)]
pub struct WireReg;
impl Rule for WireReg {
fn check(&mut self, _syntax_tree: &SyntaxTree, event: &NodeEvent) -> RuleResult {
let node = match event {
NodeEven... | true |
25bf75c065fac17617cb95caa35d93220627ba4b | Rust | leonm1/streamplay-rs | /src/main.rs | UTF-8 | 852 | 2.625 | 3 | [] | no_license | mod discover;
mod play;
mod stream;
fn main() {
println!("Welcome to streamplay");
let args: Vec<String> = std::env::args().collect();
println!("{:#?}", args[1]);
match args[1].as_str() {
"play" => match play::run() {
Ok(_) => {}
e => {
eprintln!("Play f... | true |
65eb63fd734b32db86721a9f877dd2cd11a2c647 | Rust | swfsql/test-macros-ra | /src/lib.rs | UTF-8 | 1,877 | 3.328125 | 3 | [] | no_license | //! `cargo check` runs "Ok", but RA errors.
//!
//! `cargo doc --no-deps` works "Ok":
//! Has an empty module `usages`,
//! the macros `ok_macro` and `my_macro`,
//! and two structs `CreatedByOkMacro` and `CreatedByMyMacro`.
//!
//! env info:
//!
//! rustup show: 1.55.0-x86_64-unknown-linux-gnu
//! RA: v0.2.801
//! VsC... | true |
198e84f42157ee1f4e9c3e098d3988b8bb0cf84d | Rust | liuxinbo1984/Rust-Programming-in-Action | /algorithm/divide-conquer-backtracking/leetcode_70_climbing-stairs/src/main.rs | UTF-8 | 536 | 3.078125 | 3 | [
"Apache-2.0"
] | permissive | struct Solution;
impl Solution {
pub fn climb_stairs(n: i32) -> i32 {
let mut memo: Vec<i32> = vec![0; n as usize];
return recursion(n as usize, &mut memo);
}
}
fn recursion(n: usize, memo: &mut Vec<i32>) -> i32 {
if n <= 2 {
return n as i32;
}
if memo[n-1] == 0 {
... | true |
7a4ad274e3dbb1eb0b5a1f51c4bf1724069351ef | Rust | DimChtz/brainfuck | /rust-brainpreter/src/core/memory.rs | UTF-8 | 2,265 | 3.65625 | 4 | [
"MIT"
] | permissive | use super::error::Error;
pub const MEMORY_SIZE:usize = 30000;
// Memory tape
#[derive(Debug)]
pub struct Memory {
cells: Vec<u8>,
ptr:usize,
}
impl Memory {
// Function to create and return a new Memory tape
pub fn new() -> Memory {
let mut v = Vec::<u8>::new();... | true |
c09b41e80e79dc90cb9ff2473549c1d32b68ec53 | Rust | krisnova/youki | /crates/libcontainer/src/rootless.rs | UTF-8 | 16,455 | 2.671875 | 3 | [
"Apache-2.0"
] | permissive | use crate::{namespaces::Namespaces, utils};
use anyhow::{bail, Context, Result};
use nix::unistd::Pid;
use oci_spec::runtime::{Linux, LinuxIdMapping, LinuxNamespace, LinuxNamespaceType, Mount, Spec};
use std::fs;
use std::path::Path;
use std::process::Command;
use std::{env, path::PathBuf};
#[derive(Debug, Clone, Defa... | true |
e0da0957a4155b34be17c1ae305017082e087b17 | Rust | Azure/azure-sdk-for-rust | /services/mgmt/trafficmanager/src/package_preview_2022_04/models.rs | UTF-8 | 40,496 | 2.53125 | 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 = "The allowed type DNS record types for this profile."]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(remo... | true |
55972a693950bef3098d7da73348faf8eb879e52 | Rust | MichaelNeas/laboratory | /practice/rust/variables/src/main.rs | UTF-8 | 952 | 3.3125 | 3 | [] | no_license | fn main() {
let mut x = 5;
println!("The value of x is {}", x);
x = 6;
println!("The value of x is {}", x);
const MAX_POINTS: u32 = 100_000;
println!("Constant variable {}", MAX_POINTS);
let x = 7; // shadowing
println!("The value of x is {}", x);
let spaces = " ";
let spaces ... | true |
4ab62fbfcdf2d6cca0c020b509f2119330a36ef4 | Rust | asitacko/guessing_game | /src/main.rs | UTF-8 | 1,224 | 3.25 | 3 | [] | no_license | use std::fmt::{self, Formatter, Display};
extern crate chrono;
extern crate time;
use chrono::prelude::*;
use time::Duration;
#[derive(Debug)]
struct B {
t3: i32,
}
#[derive(Debug)]
pub enum WeekdayBits {
Sun = 1,
Mon = 2,
Tue = 4,
Wed = 8,
Thu = 16,
Fri = 32,
Sat = 64,
}
#[derive(Deb... | true |
6e8161cfde51a6d03d56a4ebeee2782bf7e2b430 | Rust | aylei/leetcode-rust | /src/solution/s0087_scramble_string.rs | UTF-8 | 1,767 | 3.453125 | 3 | [
"Apache-2.0"
] | permissive | /**
* [87] Scramble String
*
* Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
*
* Below is one possible representation of s1 = "great":
*
*
* great
* / \
* gr eat
* / \ / \
* g r e at
* / \... | true |
1c1d5c2fafadc4df6410b759c365ba73474c9a2a | Rust | Gordon-x/learn_rust | /src/exercise/longest_palindrome.rs | UTF-8 | 1,081 | 3.296875 | 3 | [
"MIT"
] | permissive |
pub fn long_new(s: String) ->String {
let length = s.len();
if length < 2 {
return s;
}
let chars:Vec<char> = s.chars().collect();
if length == 2 {
if chars[0] == chars[1] {
return s;
}
return s[0..1].to_owned();
}
let (mut start, mut end, mut cur... | true |
bf1d96f382dcb1086b4d2fd123104a5daa514593 | Rust | AustinWise/AdventOfCode | /2019/day2/src/main.rs | UTF-8 | 1,196 | 3.03125 | 3 | [] | no_license | use std::error::Error;
use std::fmt;
extern crate intcode;
#[derive(Debug)]
enum MyError {
AnswerNotFound
}
impl Error for MyError {}
impl fmt::Display for MyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
MyError::AnswerNotFound => write!(f, "answer not found... | true |
b313ecd33ae9295945c92b5bbd8a0da69f070633 | Rust | doraneko94/avlsort | /src/tree.rs | UTF-8 | 11,000 | 3.453125 | 3 | [
"MIT"
] | permissive | //! AVL tree.
use crate::node::AvlNode;
use crate::traits::TreeElem;
/// AVL tree.
pub struct AvlTree<T> {
/// Root node.
pub root: Option<AvlNode<T>>,
}
impl<T: TreeElem> AvlTree<T> {
/// Create an empty AVL tree.
pub fn new() -> Self {
let root = None;
Self { root }
}
/// ... | true |
882833e2f35385d9d366f6be233090257731164f | Rust | hsyang1222/rust_example_code | /example1_3/Exercises/LJC's problem/LHJ.rs | UTF-8 | 940 | 3.578125 | 4 | [] | no_license | //이종찬 코딩 문제
// 1이상 100 이하의 정수 n, m을 입력 받아 n, m의 최소공배수와 최대공약수를 출력하는 프로그램을 작성하라.
// (범위를 벗어나는 숫자를 입력할 경우, 다시 입력 받도록 처리한다.)
use std::io;
fn main() {
let mut a = String::new();
let mut b = String::new();
println!("Pleas Big num and small num");
io::stdin()
.read_line(&mut a)
.expect("Faild... | true |
e99f247646f4210630893c30b8a4aae761b9a515 | Rust | battlecode/battlecode-hackathon | /player-rust/src/schema.rs | UTF-8 | 8,353 | 2.96875 | 3 | [] | no_license | pub type EntityID = u16;
pub type TeamID = u8;
pub type GameID = String;
pub type PlayerKey = String;
#[derive(PartialEq, Eq, Debug, Clone, Copy, Serialize, Deserialize)]
pub struct Location {
pub x: i32,
pub y: i32,
}
#[derive(PartialEq, Eq, Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all="lo... | true |
3929496934e690845b3388745fd848b76dc62ee0 | Rust | Taneb/zombiesplit | /src/model/time/carry.rs | UTF-8 | 926 | 3.8125 | 4 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Functionality for dealing with carries between time fields.
/// Represents the result of a time computation that has generated carry.
pub struct Carry<T> {
/// The value for which carry has been computed.
pub value: T,
/// The carry amount.
pub carry: u32,
/// The original input.
pub origin... | true |
a672983a00825d33bf24046523347c27a22a1908 | Rust | marionebl/rust-book-exercises | /8_2_strings/src/main.rs | UTF-8 | 1,236 | 3.84375 | 4 | [] | no_license | use std::ops::Add;
fn main() {
let mut _s = String::new();
let _bar = "bar";
_s.push_str(&_bar);
println!("_s is {}, _bar is {}", _s, _bar);
let data = "initial contents";
let _t = data.to_string();
let _u = "initial_contents".to_string();
let _v = String::from(data);
let s1 = St... | true |
8b6a13f2536be8abc6f4b3af4fbf6a83b3a54874 | Rust | ccmlm/hotstuff-consensus | /hs-data/src/msg.rs | UTF-8 | 1,340 | 3.0625 | 3 | [] | no_license | use serde::{Deserialize, Serialize};
use crate::{ReplicaID, ViewNumber};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Context {
pub from: ReplicaID,
pub to: DeliveryType,
// Latest view.
pub view: ViewNumber,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DeliveryType {
... | true |
ac34511f069048bec34e5cf0e209f607493695cd | Rust | lemonrock/intel-seapi | /workspace/intel-seapi/src/Identifier.rs | UTF-8 | 1,760 | 2.796875 | 3 | [
"MIT"
] | permissive | // This file is part of intel-seapi. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/intel-seapi/master/COPYRIGHT. No part of intel-seapi, including this file, may be copied, modified, propagated, or distri... | true |
c1dd78935d4b3264caf114ab879394baeb741a6e | Rust | MacTuitui/nannou | /examples/laser/laser_ilda_idtf.rs | UTF-8 | 3,750 | 2.875 | 3 | [] | permissive | //! An example of reading files of the ILDA Image Data Transfer Format and playing them back with
//! nannou.
//!
//! Specify a directory containing `.ild` or `.ILD` files to play them with this example. E.g.
//!
//! ```
//! cargo run --release -p examples --example laser_ilda_idtf -- /path/to/ilda/files
//! ```
use n... | true |
8bebfbd27dde821db21ec4340034caf9c2e7810e | Rust | spring-epfl/arti-tweaks | /tor-circmgr/src/impls.rs | UTF-8 | 3,705 | 2.703125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] | permissive | //! Implement traits from [`crate::mgr`] for the circuit types we use.
use crate::mgr::{self};
use crate::usage::{SupportedCircUsage, TargetCircUsage};
use crate::{DirInfo, Error, Result};
use async_trait::async_trait;
use rand::{rngs::StdRng, SeedableRng};
use std::convert::TryInto;
use std::sync::Arc;
use std::time:... | true |
2f336bd287c6374e36bbc5fa2d954e6ef4843af4 | Rust | Will-Banksy/intpack | /src/main.rs | UTF-8 | 291 | 2.609375 | 3 | [] | no_license | fn main() {
use intpack::pack;
let result = pack::u8_to_u32(&[0xff, 0x00, 0xff, 0x00]);
println!("Result: {}", result);
use intpack::unpack;
let result = unpack::u32_to_u8(0xff00ff00);
println!("Result: [0]:{}, [1]:{}, [2]:{}, [3]:{}", result[0], result[1], result[2], result[3]);
} | true |
93561af682b5eb59a99717eea911437b18730537 | Rust | Drumato/elf-utilities | /src/section/base.rs | UTF-8 | 3,645 | 3.125 | 3 | [
"MIT"
] | permissive | use super::{Contents32, Contents64, Section32, Section64, Shdr32, Shdr64, Type};
#[derive(Debug, Clone)]
pub(crate) struct Section {
pub name: String,
pub header: Shdr,
pub contents: Contents,
}
#[derive(Debug, Clone)]
pub(crate) enum Shdr {
Shdr64(Shdr64),
Shdr32(Shdr32),
}
#[derive(Debug, Clon... | true |
2253b0e2478555918b44e36118e3a8180de94702 | Rust | sunnyrust/releasenote | /src/main.rs | UTF-8 | 7,199 | 2.703125 | 3 | [] | no_license | #[macro_use]
extern crate clap;
extern crate libc;
extern crate chrono;
use std::error::Error;
use std::fs::File;
use std::io::prelude::*;
use rusqlite::{params,Connection,NO_PARAMS};
use serde::{Deserialize, Serialize};
//use time::Timespec; //Also, it should be noted, that time v0.1.* must be used, because Timespec ... | true |
11fe9f02c0b6036b96402c10018a738d90f3ae67 | Rust | wtsoli/max_num_non_overlap_substring | /src/lib.rs | UTF-8 | 6,993 | 3.265625 | 3 | [] | no_license | mod front_of_house;
//use crate::front_of_house::DerefMutExample;
pub struct Solution {}
use std::collections::HashSet;
impl Solution {
fn build_letter_pos(s: &str, letter_pos: &mut Vec<Vec<usize>>) {
for (position, letter) in s.chars().enumerate() {
let index = letter as usize - 97;
... | true |
7d43ea369a3f0eefc247128611652c7ea69388f8 | Rust | rkday/adventofcode2020 | /src/bin/day10.rs | UTF-8 | 1,799 | 3.140625 | 3 | [
"Apache-2.0"
] | permissive | #![feature(split_inclusive)]
use itertools::Itertools;
use std::collections::HashSet;
fn bruteforce(v: Vec<u64>, mut parent: HashSet<Vec<u64>>) -> HashSet<Vec<u64>> {
let mut vecs = HashSet::new();
for idx in 1..(v.len() - 1) {
let diff = v[idx+1] - v[idx-1];
if diff < 4 {
let mut... | true |
f5338315401fa24a51799df092cd28971b56b4d1 | Rust | energiacte/cteepbd | /src/vecops.rs | UTF-8 | 4,686 | 2.96875 | 3 | [
"MIT"
] | permissive | // Copyright (c) 2018-2022 Ministerio de Fomento
// Instituto de Ciencias de la Construcción Eduardo Torroja (IETcc-CSIC)
// 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 ... | true |
48428b16130c5f69c19b6b478b8084b14a4e7378 | Rust | zerosign/credstash | /src/types.rs | UTF-8 | 875 | 2.546875 | 3 | [
"MIT"
] | permissive | use futures::{Future, Stream};
trait KeyService {
fn decrypt(&self, buffer: &[u8]) -> Future<Item, Error> ;
fn encrypt<T>(&self, T) where ;
}
pub struct FilterBuilder {
fn build(&self) -> Cursor<Item = Self::Item, Error = Error>;
}
pub struct Cursor {}
trait Repository {
type Item;
fn fetch<S>(... | true |
0787a0808f7c20232b4941a3d0c79249959bbadf | Rust | standard-ai/hedwig-rust | /src/validators/prost.rs | UTF-8 | 7,897 | 3.34375 | 3 | [
"Apache-2.0"
] | permissive | //! Validation and decoding for messages encoded with protobuf using [`prost`](::prost)
//!
//! ```
//! use hedwig::validators::prost::{ProstValidator, ProstDecoder, ExactSchemaMatcher};
//! # use uuid::Uuid;
//! # use std::time::SystemTime;
//!
//! #[derive(Clone, PartialEq, ::prost::Message)]
//! struct MyMessage {
/... | true |
b4c1d4d935c64f83447f4213e7a1bdf19927153f | Rust | qingyunha/socks5 | /rs-async-std/src/main.rs | UTF-8 | 3,880 | 2.671875 | 3 | [] | no_license | use async_std::io;
use async_std::net::{IpAddr, Ipv4Addr, TcpListener, TcpStream};
use async_std::prelude::*;
use async_std::task;
use std::error::Error;
use std::str;
fn main() {
match task::block_on(server()) {
Ok(_) => (),
Err(e) => println!("handle error {}", e),
}
}
async fn server() -> R... | true |
279d3fc999d6435289f5285803a7410664d2efa5 | Rust | 0xd34d10cc/nox-rs | /src/syntax/pascal.rs | UTF-8 | 5,255 | 2.828125 | 3 | [
"MIT"
] | permissive | // Statements ::= Statement (';' Statement)*
// Statement ::= Skip | IfElse | While | For | Assign | Read | Write | Call
// Skip ::= 'skip'
// IfElse ::= 'if' Expr 'then' Statements ('elif' Expr 'then' Statements)* ['else' Statements] 'fi'
// While ::= 'while' Expr 'do' Statements 'od'
// For ::= 'for' Statement ',' E... | true |
5516803bcc5f99c152cec3c075054d2f17a8ad4f | Rust | Mcmulla0030/paat | /paat-cli/src/inputs.rs | UTF-8 | 1,152 | 3 | 3 | [] | no_license | use chrono::NaiveDate;
use dialoguer::{theme::ColorfulTheme, Input, Select};
use paat_core::{actors::event::Direction, datetime::get_naive_date};
use std::{io, str::FromStr};
pub fn input_departure_date() -> io::Result<NaiveDate> {
let date_input: String = Input::new()
.with_prompt("Please enter the date t... | true |
4e9f54fabade25de9d23c1fe0b6eeb58ce9f7d81 | Rust | MugenU/rust-callgraph-benchmark | /src/generics/src/base.rs | UTF-8 | 788 | 3.21875 | 3 | [
"MIT"
] | permissive | use structs::lib::One as ForeignOne;
use traits::lib::bounds::BoundTrait as ForeignBoundTrait;
pub struct One;
pub struct Two;
pub trait BoundTrait {
fn method(&self) -> i32;
}
impl BoundTrait for ForeignOne {
fn method(&self) -> i32 {
1
}
}
impl ForeignBoundTrait for One {
fn method(&self) ... | true |
02ca7bad4a330cd1b44ae1c4e7d1db2e83b45a48 | Rust | sile/stun_codec | /src/constants.rs | UTF-8 | 730 | 2.625 | 3 | [
"MIT"
] | permissive | /// The magic cookie value.
///
/// > The magic cookie field **MUST** contain the fixed value `0x2112A442` in
/// > network byte order.
/// > In [RFC 3489](https://tools.ietf.org/html/rfc3489), this field was part of
/// > the transaction ID; placing the magic cookie in this location allows
/// > a server to detect if ... | true |
d0893400f71a2141ebcf54463d52d36cf31c8326 | Rust | fudgepop01/brawllib_rs | /src/bres.rs | UTF-8 | 9,287 | 2.65625 | 3 | [
"MIT"
] | permissive | use fancy_slice::FancySlice;
use crate::util;
use crate::resources;
use crate::chr0::*;
use crate::mdl0::*;
use crate::plt0::*;
pub(crate) fn bres(data: FancySlice) -> Bres {
let endian = data.u16_be(0x4);
let version = data.u16_be(0x6);
//let size = data.u32_be(0x8);
let root_o... | true |
72e8502d33578351380d3d67d8841718e472b394 | Rust | wspeirs/fishermann | /utils/csv_search/src/main.rs | UTF-8 | 3,071 | 3.15625 | 3 | [
"MIT"
] | permissive | use std::env;
use std::io::BufReader;
use std::fs::File;
use std::mem;
use rayon::prelude::*;
use memmap::MmapOptions;
use smallvec::{smallvec, SmallVec};
use std::collections::HashMap;
enum CastleType {
KING,
QUEEN
}
#[derive(Ord, PartialOrd, Eq, PartialEq)]
enum Elo {
Beginner,
Intermediate,
Ad... | true |
0cc8d64b55e6db21cf27e72ceb99df4a170afc29 | Rust | PartyLich/tetrs | /tetrs/src/component.rs | UTF-8 | 2,866 | 2.6875 | 3 | [] | no_license | use std::collections::VecDeque;
use ecs::{
component_manager::Manager,
types::{Cell, Vector2},
ComponentRegistry,
};
pub type ColorComponent = Manager<Cell>;
#[derive(Debug, Default)]
pub struct Size(pub u32);
pub type SizeComponent = Manager<Size>;
pub type Position = Vector2<i32>;
pub type PositionCom... | true |
e1cbb7f906f9de8cef08d0023fe2206b26ccfa88 | Rust | chromium/chromium | /third_party/rust/toml/v0_5/crate/tests/enum_external_deserialize.rs | UTF-8 | 6,312 | 2.78125 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"GPL-1.0-or-later",
"LGPL-2.0-or-later",
"BSD-3-Clause"
] | permissive | #[macro_use]
extern crate serde_derive;
extern crate toml;
#[derive(Debug, Deserialize, PartialEq)]
struct OuterStruct {
inner: TheEnum,
}
#[derive(Debug, Deserialize, PartialEq)]
enum TheEnum {
Plain,
Tuple(i64, bool),
NewType(String),
Struct { value: i64 },
}
#[derive(Debug, Deserialize, Partia... | true |
84c0fe0f2f5202ca74efc353eeee74a97ecf5f71 | Rust | adrianbrink/rustlings | /src/tests.rs | UTF-8 | 754 | 3.9375 | 4 | [] | no_license | fn is_even(num: i32) -> bool {
num % 2 == 0
}
fn times_two(num: i32) -> i32 {
num * 2
}
#[cfg(test)]
mod tests {
#[test]
fn you_can_assert() {
assert!(true);
}
#[test]
fn you_can_assert_eq() {
assert_eq!(1, 1);
}
#[test]
fn is_true_when_even() {
use su... | true |
a2906ba5b86b61da065e5dc8431e1cb1070f68bd | Rust | programble/patience | /src/game/klondike/game.rs | UTF-8 | 6,421 | 2.859375 | 3 | [
"ISC"
] | permissive | use std::mem;
use card::{Rank, Card, Face, Set, Pile};
use game::Game;
use super::{Klondike, Draw, Play, Foundation, Tableau};
impl Game for Klondike {
type Rules = Draw;
type Play = Play;
fn new(draw: Draw) -> Self {
Klondike {
draw: draw,
stock: Set::new().map(Face::Down... | true |
485c5fcc4defc82159277e4d9aca78a4d4bc27be | Rust | brahms116/PortfolioRust | /src/utils/road_data.rs | UTF-8 | 800 | 2.546875 | 3 | [] | no_license | use crate::utils::direction::Direction;
use crate::utils::road_joints::Joint;
use crate::utils::road_joints::RoadJoints;
use crate::utils::transform::SinglePointTransform;
pub struct RoadData {
pub joints: RoadJoints,
pub speed_limit: f64,
}
pub struct RoadDynamicData {
pub controlled_segments: Vec<i32>,
pub cycl... | true |
a1a37d448079b1fa3f3f7f562e556aa113b0e7ff | Rust | muskanmahajan37/rsass | /tests/spec/core_functions/color/rgba/one_arg/special_functions.rs | UTF-8 | 12,566 | 2.71875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //! Tests auto-converted from "sass-spec/spec/core_functions/color/rgba/one_arg/special_functions.hrx"
#[allow(unused)]
fn runner() -> crate::TestRunner {
super::runner()
}
mod alpha {
#[allow(unused)]
use super::runner;
mod calc {
#[allow(unused)]
use super::runner;
#[test]
... | true |
2a7a8752786268049ed7dab389fa321ad8e6e144 | Rust | TahsinTariq/rust-notes | /functions/src/main.rs | UTF-8 | 405 | 3.484375 | 3 | [] | no_license | fn main() {
let a: [i32; 5] = [3; 5];
println!("{}", 53u8);
for i in 1..5 {
println!("{}", i);
}
for i in a.iter() {
print!("{}", i);
}
let x = {
let mut p = 0;
for i in 1..10 {
p += i;
}
p
};
println!("\nOwO {}", x);
}
// ... | true |
7280e743cc4217c655ed7842013e8ada044c575e | Rust | yeyande/advent-of-code | /2020/01/src/main.rs | UTF-8 | 1,347 | 3.5 | 4 | [] | no_license | use std::fs;
fn main() {
let contents = fs::read_to_string("input.txt").unwrap();
let values: Vec<i32> = contents
.lines()
.into_iter()
.map(|x| x.parse().unwrap())
.collect();
let (x, y, z) = get_triple_with_sum(values, 2020).unwrap();
println!("{}", x * y * z);
}
fn g... | true |
436e5c4be178da5e1ec84ae5f180a47650eb8c3c | Rust | Kintaro/rbrt | /src/core/diffgeom.rs | UTF-8 | 3,535 | 2.5625 | 3 | [] | no_license | use std::rc::Rc;
use std::cell::RefCell;
use geometry::{ Normal, Point, RayDifferential, Vector, normalize, cross, dot, solve_linear_system };
use shape::Shape;
#[deriving(Clone)]
pub struct DifferentialGeometry {
pub p: Point,
pub nn: Normal,
pub u: f32,
pub v: f32,
pub shape: Option<Rc<RefC... | true |
d3534a4e59d9cf2a36e66cfd09801258107ef9d5 | Rust | fabianschuiki/llhd | /src/assembly/reader.rs | UTF-8 | 19,521 | 2.59375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | // Copyright (c) 2017-2021 Fabian Schuiki
//! Temporary representation of LLHD IR after parsing.
use crate::{
ir::{self, Opcode, Signature, UnitBuilder, UnitName},
ty::Type,
value::{IntValue, TimeValue},
};
use num::{BigInt, BigRational};
use std::collections::HashMap;
#[derive(Default)]
pub struct Conte... | true |
ed864cd5adadb6b74abfb49c219fb39445aa5cfc | Rust | oc-soft/glrs | /src/matrixi.rs | UTF-8 | 6,137 | 3.109375 | 3 | [] | no_license | use crate::matrix::MatrixError;
use std::cell::RefCell;
use std::rc::Rc;
/// represent matrix
#[readonly::make]
pub struct MatrixI {
component: Rc<RefCell<Vec<f64>>>,
pub col_count: usize,
}
// Matrix implementatin
impl MatrixI {
/// create matrix instance to bind vector
pub(crate) fn bind_with_col_co... | true |
e536a16144c36472f181a43bb36c13b3cffd2edb | Rust | bonsairobo/ilattice3 | /src/vox.rs | UTF-8 | 2,071 | 2.65625 | 3 | [
"MIT"
] | permissive | use crate::{prelude::*, Extent, Indexer, Point, VecLatticeMap};
use dot_vox::*;
impl<I: Indexer> Into<DotVoxData> for VecLatticeMap<VoxColor, I> {
fn into(self: Self) -> DotVoxData {
let size = *self.get_extent().get_local_supremum();
// Voxel coordinates are limited to u8.
assert!(size.x ... | true |
e1b4bd9690c1ea4440b1437731082bb5f8a21c27 | Rust | denglitong/the-book | /enums/src/main.rs | UTF-8 | 5,183 | 3.984375 | 4 | [] | no_license | // Rust's enums are most similar to algebraic data types in functional languages, such as Haskell
// enums get its name because we can enumerates all the possible variants
//#[derive(Debug)]
//enum IpAddrKind {
// V4,
// V6,
//}
//
//struct IpAddr {
// kind: IpAddrKind,
// address: String,
//}
//fn route(... | true |
2769cd6e64c68a9ac59b8b393a843ef9933c30a7 | Rust | rust-av/rust-av | /codec/src/decoder.rs | UTF-8 | 5,204 | 2.890625 | 3 | [
"MIT"
] | permissive | use std::collections::HashMap;
use av_data::frame::ArcFrame;
use av_data::packet::Packet;
use crate::common::CodecList;
use crate::error::*;
/// Used to interact with a decoder.
pub trait Decoder: Send + Sync {
// TODO support codec configuration using set_option
// fn open(&mut self) -> Result<()>;
/// ... | true |
bf5fe0f6e5f9dde544b314e26d35cbcfb7a49ad3 | Rust | PayasR/rust_road_router | /engine/tests/link_speed_estimates.rs | UTF-8 | 8,744 | 2.8125 | 3 | [
"BSD-3-Clause"
] | permissive | extern crate rust_road_router;
use rust_road_router::link_speed_estimates::*;
#[test]
fn check_for_empty_errors() {
let links = vec![];
let traces = vec![];
assert!(estimate_iter(Box::new(links.iter()), Box::new(traces.iter())).is_err());
}
#[test]
fn two_points_one_link() {
let links = vec![LinkData... | true |
bde9d772e657a170c36aa889ba0c4bec6a4c31f6 | Rust | wotsushi/competitive-programming | /abc/134/d.rs | UTF-8 | 1,708 | 3.015625 | 3 | [
"MIT"
] | permissive | macro_rules! get {
(Vec<$t:ty>) => {
{
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.split_whitespace()
.map(|t| t.parse::<$t>().unwrap())
.collect::<Vec<_>>()
}
};
($t:ty) => {
... | true |
6810fc47f31563c10542dacf8c4ec561762cff0b | Rust | MrBearing/TheRustProgrammingLanguage | /projects/ch03/excercise/src/main.rs | UTF-8 | 714 | 3.28125 | 3 | [] | no_license |
use excercise::temp::Temprature;
extern crate numeral;
use numeral::Cardinal;
use excercise::twelve_days;
fn main() {
println!("Hello, world! {} ", (1+2)*3);
let c_0_degree = Temprature::from_celsius(0.0);
println!("{} F",c_0_degree.as_fahrenheit());
let f50_degree = Temprature::from_fahrenheit(50.0);... | true |
dd11c18a74ed4e45e967f736733e7895745899ab | Rust | rklaehn/tag-index | /src/main.rs | UTF-8 | 15,000 | 3.234375 | 3 | [] | no_license | use maplit::btreeset;
use reduce::Reduce;
use serde::{Deserialize, Deserializer, Serialize, Serializer, de::DeserializeOwned};
use std::{
collections::{BTreeMap, BTreeSet},
ops::{BitAnd, BitOr},
};
/// a compact index
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Index {
/// the strings table
strin... | true |
1b324e3eee89a3cc6e1f16602690c09a32d5a380 | Rust | iqlusioninc/abscissa | /core/src/testing/regex.rs | UTF-8 | 940 | 3.265625 | 3 | [
"Apache-2.0"
] | permissive | //! Regex newtype for simplifying conversions from the `regex` crate
use std::{fmt, ops::Deref};
/// Regex newtype (wraps `regex::Regex`)
#[derive(Clone)]
pub struct Regex(regex::Regex);
impl Regex {
/// Compile a regular expression
pub fn new(re: &str) -> Result<Self, regex::Error> {
regex::Regex::n... | true |
ba05bc5381e9cc711e4d40a236aa3aa40e4e12e1 | Rust | starblue/advent_of_code | /a2018/src/bin/a201811b.rs | UTF-8 | 2,467 | 3.609375 | 4 | [] | no_license | use std::iter::repeat;
const SERIAL: i64 = 2568;
fn power_level(serial: i64, x: i64, y: i64) -> i64 {
let rack_id = x + 10;
let pl1 = rack_id * y + serial;
let pl2 = pl1 * rack_id;
let digit = (pl2 / 100) % 10;
digit - 5
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
struct Data {
sum: i64,
... | true |
47be42275acb2c6ea6cd7dfcdaf508ba1f18c396 | Rust | bookdude13/rust-sfml | /src/graphics/view.rs | UTF-8 | 9,075 | 2.703125 | 3 | [
"Zlib"
] | permissive | // Rust-SFML - Copyright (c) 2013 Letang Jeremy.
//
// The original software, SFML library, is provided by Laurent Gomila.
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from
// the use of this software.
//
// Perm... | true |
2e59d31a75549b01ab4804885fc30d00b66d793d | Rust | bucho666/rust-roguelike | /src/entity.rs | UTF-8 | 854 | 3.28125 | 3 | [] | no_license | use std::any::Any;
use std::collections::HashMap;
pub type EntityId = u64;
pub struct EntitySystem {
entities: HashMap<EntityId, Box<Any>>,
last_id: EntityId,
}
impl EntitySystem {
pub fn new() -> Self {
EntitySystem {
entities: HashMap::new(),
last_id: 1,
}
}
... | true |
2d6e77aa8b018a6abc92beaf825c68505a2e1c85 | Rust | not-fl3/glam-rs | /tests/mat3.rs | UTF-8 | 8,445 | 2.65625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | mod support;
use glam::f32::*;
use support::deg;
const IDENTITY: [[f32; 3]; 3] = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]];
const MATRIX: [[f32; 3]; 3] = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]];
const ZERO: [[f32; 3]; 3] = [[0.0; 3]; 3];
#[test]
fn test_mat3_align() {
use std::mem;
if... | true |
6dbfc832597890c2d2d131f3ca7377d2f19e76b9 | Rust | pi-pi3/julia-rs | /src/error.rs | UTF-8 | 5,980 | 3.203125 | 3 | [
"Zlib",
"LicenseRef-scancode-unknown-license-reference"
] | permissive |
//! This module provides types necessary for error checking and debugging.
use std::fmt;
use std::result;
use std::error;
use std::io;
use std::char::CharTryFromError;
use std::string::FromUtf8Error;
use std::ffi::{FromBytesWithNulError, IntoStringError, NulError};
use std::sync::PoisonError;
use std::rc::Rc;
use ap... | true |
c9d59baa51bf4c02ca0495ce5677f9a68541337b | Rust | konkers/pollendina | /src/widget/constellation.rs | UTF-8 | 5,444 | 2.765625 | 3 | [
"MIT"
] | permissive | use std::cmp::Ordering;
use druid::kurbo::{Point, Rect, Size};
use druid::{
BoxConstraints, Data, Env, Event, EventCtx, LayoutCtx, LifeCycle, LifeCycleCtx, PaintCtx,
UpdateCtx, Widget, WidgetPod,
};
use super::list_iter::ListIter;
pub trait Star {
fn pos(&self) -> (f64, f64);
fn radius(&self) -> f64... | true |
c2e0886c2d408c139a662df620ead4e0720a422f | Rust | kprav33n/aoc18.rs | /src/day12.rs | UTF-8 | 3,781 | 3.234375 | 3 | [] | no_license | use std::fmt;
use std::str::FromStr;
/// Find the sum of the numbers of all pots which contain a plant after given
/// number of generations.
pub fn sum_pots_after(input: &str, gen: usize) -> i64 {
let parts: Vec<&str> = input.split("\n\n").collect();
let mut init_state_str = parts[0];
init_state_str = ini... | true |
21e9bc08f0c7f34b4f7477f8f3e32d659eb401fe | Rust | chibby0ne/exercism | /rust/acronym/src/lib.rs | UTF-8 | 387 | 2.90625 | 3 | [
"MIT"
] | permissive | pub fn abbreviate(phrase: &str) -> String {
phrase
.split(|c: char| c.is_whitespace() || c == '-')
.flat_map(|w| {
w.chars().take(1).chain(
w.chars()
.skip_while(|c| c.is_uppercase())
.filter(|c| c.is_uppercase()),
)
... | true |
1ca5adf5dc344bf69f8a9f2ec8f1eb771e646bff | Rust | hurou927/atool-rs | /src/option.rs | UTF-8 | 1,683 | 2.828125 | 3 | [
"MIT"
] | permissive | use clap::Clap;
use env_logger::Builder;
use env_logger::Env;
use std::io::Write;
use std::path::PathBuf;
/// A basic example
#[derive(Clap, Debug, Clone)]
#[clap(
name = "ratool",
version = "1.0",
author = "hurou927 <god.be.with.ye.fs@gmail.com>"
)]
pub struct Opt {
#[clap(subcommand)]
pub subcmd:... | true |
a3fd147f8cfc4c332472b37616edaef33e173914 | Rust | attilahorvath/exercism-rust | /robot-simulator/src/lib.rs | UTF-8 | 1,686 | 3.84375 | 4 | [
"MIT"
] | permissive | #[derive(Debug, PartialEq)]
pub enum Direction {
North,
East,
South,
West,
}
pub struct Robot {
position: (isize, isize),
direction: Direction,
}
use Direction::*;
impl Robot {
pub fn new(x: isize, y: isize, direction: Direction) -> Self {
Self {
position: (x, y),
... | true |
69e02538962bf5d07cf9b0332219081ab9ad5695 | Rust | tianhuil/prisma | /server/prisma-rs/query-engine/connectors/sql-connector/src/mutaction/delete_actions.rs | UTF-8 | 1,622 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | use crate::{error::SqlError, SqlResult};
use prisma_models::prelude::*;
use prisma_query::ast::*;
/// Checks to be executed when deleting data.
pub struct DeleteActions;
impl DeleteActions {
/// A model can be required in another model, preventing the deletion.
/// Therefore we must check if any other model i... | true |
ed544f355edf7d046826446f330d00ecdd972339 | Rust | 27factorial/chat_server | /src/server.rs | UTF-8 | 13,752 | 2.90625 | 3 | [] | no_license | extern crate hashbrown;
extern crate rand;
use crate::command;
use self::ServerError::*;
use command::{Command, CommandHandler};
use hashbrown::HashMap;
use rand::Rng;
use std::convert::TryFrom;
use std::fmt;
use std::io;
use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;
use std::sync::m... | true |
c54cd6f9bca0b3cde61df377d5b5bae51cd5bdfa | Rust | mikhaildubov/rust-playground | /rust-lang-book/ch04-03-slices/src/main.rs | UTF-8 | 1,939 | 3.875 | 4 | [] | no_license | fn test_basic_slices() {
let s = String::from("hello, world!");
let hello = &s[..5]; // end exclusive
let world = &s[7..=11]; // end inclusive
println!("{} / {}, {}", s, hello, world);
}
fn test_breaking_utf_slice() {
let cats = String::from("😻😻");
println!("{}", cats);
// One cat... | true |
6f3faf5343463a27e4166e31317502c7b31f9de7 | Rust | UnTraDe/repotool-rs | /src/crates.rs | UTF-8 | 1,290 | 3.015625 | 3 | [] | no_license | use std::fs::File;
use std::io::prelude::*;
use crate::common;
fn get_crate_repository_url(crate_name: &str) -> Option<String> {
let url = format!("https://crates.io/api/v1/crates/{}", crate_name);
let (resp, _) = common::request_get(&url).expect(&format!("failed: {} ", url));
let repos: serde_json::Value = serde_j... | true |
7ab321b4ee7dfe79b6dd0f6277813acaa9d52ee9 | Rust | cargo-generate/cargo-generate | /src/git/utils.rs | UTF-8 | 3,152 | 3.109375 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use anyhow::Context;
use anyhow::Result;
use std::path::{Path, PathBuf};
use git2::Repository;
use tempfile::TempDir;
use super::RepoCloneBuilder;
pub fn tmp_dir() -> std::io::Result<tempfile::TempDir> {
tempfile::Builder::new().prefix("cargo-generate").tempdir()
}
/// deals with `~/` and `$HOME/` prefixes
pub ... | true |
9c22acdfed0174476b9d6244c5e4269a73a37a51 | Rust | njam/thespis_impl | /src/addr.rs | UTF-8 | 6,723 | 3 | 3 | [
"Unlicense"
] | permissive | use crate::{ import::*, Inbox, envelope::*, error::* };
/// Reference implementation of thespis::Address<A, M>.
/// It can receive all message types the actor implements thespis::Handler for.
/// An actor will be dropped when all addresses to it are dropped.
//
pub struct Addr< A: Actor >
{
mb : mpsc::UnboundedSen... | true |
01c21974fbf21dec2c9898445f05a608e48a83d1 | Rust | nettan20/rust-itertools | /src/linspace.rs | UTF-8 | 1,383 | 3.546875 | 4 | [
"MIT",
"Apache-2.0"
] | permissive | use super::misc::ToFloat;
use std::ops::{Add, Sub, Div};
/// An iterator of a sequence of evenly spaced floats.
///
/// Iterator element type is `F`.
pub struct Linspace<F> {
start: F,
step: F,
len: usize,
}
impl<F> Iterator for Linspace<F> where
F: Copy + Add<Output=F>,
{
type Item = F;
#[in... | true |
dbcf8a8001b26163acde1062d6a468e18177c33b | Rust | nathdobson/crossword | /src/util/bag.rs | UTF-8 | 976 | 3.546875 | 4 | [] | no_license | use std::collections::HashMap;
use std::collections::hash_map::Values;
pub struct BagToken(usize);
pub struct Bag<T> {
map: HashMap<usize, T>,
next: usize,
}
impl<T> Bag<T> {
pub fn new() -> Self {
Bag {
map: HashMap::new(),
next: 0,
}
}
pub fn insert(&mut ... | true |
67e273ddcef97c23c57d151f61bc4ed2373244d9 | Rust | ferrous-systems/imxrt1052 | /src/pxp/ps_scale/mod.rs | UTF-8 | 5,284 | 2.609375 | 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::PS_SCALE {
#[doc = r" Modifies the contents of the register"]
#[inline]
pub fn modify<F>(&self, f: F)
where
for<'w> F: FnOnce(&R, &'w ... | true |
fc74336b743b1bc22a8053b2f4a7426541e1b536 | Rust | sbechet/ibm437 | /benches/bench_mapping.rs | UTF-8 | 5,624 | 2.59375 | 3 | [
"MIT"
] | permissive | use criterion::{black_box, criterion_group, criterion_main, Criterion};
#[path = "../src/char_offset.rs"]
mod char_offset;
use char_offset::char_offset_impl;
pub fn char_offset_impl_original(c: char) -> usize {
match c {
' '..='~' => c as usize,
'\u{0000}' => 0x00,
'☺' => 0x01,
'☻'... | true |
5d1799f0dbec1d053dd5e43064fad16d8bdde851 | Rust | taodo2291/adventofcode | /examples/day_10.rs | UTF-8 | 1,876 | 3.15625 | 3 | [] | no_license | use std::collections::HashMap;
use std::fs::File;
use std::io::{prelude::*, BufReader};
fn main() {
let mut input = read_input("input/10.txt").expect("Could not read input file!!");
input.push(0);
input.sort();
println!(
"Part 1: {}",
find_multiply_one_three_differences_jolt_count(&inp... | true |
35c4c070ff3cb07f829bcf5a2d6ea8153050b6e6 | Rust | GHvW/basix-T4 | /src/encode.rs | UTF-8 | 4,884 | 3.484375 | 3 | [
"MIT"
] | permissive |
fn encode_first(first: u8) -> usize {
usize::from((first & 0b11111100) >> 2)
}
fn encode_second(first: u8, second: u8) -> usize {
usize::from(((first & 0b00000011) << 4) | ((second & 0b11110000) >> 4))
}
fn encode_third(second: u8, third: u8) -> usize {
usize::from(((second & 0b00001111) << 2) | ((third ... | true |
b17c96e050ee3065db1a9d0f3d926d334e2efe73 | Rust | EFanZh/Introduction-to-Algorithms | /src/chapter_16_greedy_algorithms/section_16_3_huffman_codes/mod.rs | UTF-8 | 2,900 | 3.765625 | 4 | [] | no_license | use crate::utilities::KeyValuePair;
use std::cmp::Reverse;
use std::collections::BinaryHeap;
pub mod exercises;
#[derive(PartialEq, Eq, Debug)]
pub enum NodeContent<T> {
Node {
left: Box<TreeNode<T>>,
right: Box<TreeNode<T>>,
},
Leaf {
key: T,
},
}
#[derive(PartialEq, Eq, Debu... | true |
a1d477a2c6e028f7e002a491150cd83ac5820c0b | Rust | rodrigocfd/winsafe | /src/kernel/utilities/path.rs | UTF-8 | 11,168 | 3.25 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! File path utilities.
//!
//! Some of the functions are similar to [`std::path::Path`] ones, but here they
//! work directly upon [`&str`](str) instead of [`&OsStr`](std::ffi::OsStr).
use crate::co;
use crate::decl::*;
use crate::guard::*;
use crate::prelude::*;
/// Returns an iterator over the files and... | true |
81828090816d6cc24a7079c2dff5c88020af2ae3 | Rust | ddmin/CodeSnippets | /Advent-of-Code/Advent2021/src/days/day03.rs | UTF-8 | 2,033 | 3.3125 | 3 | [] | no_license | const INPUT: &str = include_str!("../../inputs/day03.txt");
fn max_bit(input: &[i32], pos: usize) -> i32 {
let mut count = [0, 0];
for &bit in input.iter() {
count[bit as usize >> pos & 1] += 1;
}
(count[0] <= count[1]) as i32
}
fn vec_to_i32(vec: &[i32]) -> i32 {
let mut sum = 0;
for ... | true |
8cf36d2ed5492cf073cf0d38183395b119d7092a | Rust | jjdredd/math536.rs | /cg/cg.rs | UTF-8 | 3,727 | 3.453125 | 3 | [] | no_license | use std::vec::Vec;
use std::clone::Clone;
use std::ops::Mul;
struct MCoor {
row : usize,
col : usize,
}
pub struct CSM {
N : usize,
C : Vec<MCoor>,
Elem : Vec<f64>,
}
impl CSM {
// construct a new CSM
pub fn new(Size : usize) -> CSM {
CSM {
N : Size,
C : Ve... | true |
a3c0d0c8b228a43bc612bc3cce5521768af8a5ce | Rust | Greast/r-graph | /src/dev/node.rs | UTF-8 | 379 | 3.09375 | 3 | [
"MIT"
] | permissive | #[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct Node<Data, From, To> {
pub data: Data,
pub from: From,
pub to: To,
}
impl<Data, Edge> Node<Data, Edge, Edge> {
pub fn other(&self, key: &Edge) -> &Edge
where
Edge: PartialEq,
{
if key == &self.from {
&self.to... | true |
6c1644c2e2bc126aafdac188aa3d377152f783f7 | Rust | ajfrantz/advent2018 | /src/bin/13.rs | UTF-8 | 7,651 | 3.359375 | 3 | [] | no_license | use std::env;
use std::fmt;
use std::fs::File;
use std::io::prelude::*;
use failure::Error;
#[derive(Debug, Copy, Clone)]
enum TrackType {
Vertical,
Horizontal,
Clockwise,
CounterClockwise,
Junction,
}
impl TrackType {
fn from(c: char) -> Option<TrackType> {
match c {
'|' ... | true |
26ec8bc958d29d59a792875f30c5d0342925fcd3 | Rust | lunacookies/fjord-repl | /src/bin/fjord.rs | UTF-8 | 1,720 | 3 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use atty::Stream;
use fjord::env::Env;
use fjord::parser::Parser;
use std::io::{self, Read, Write};
use std::path::PathBuf;
fn main() -> io::Result<()> {
let mut stdin = io::stdin();
let mut stdout = io::stdout();
let search_path = vec![
PathBuf::from("/usr/local/sbin"),
PathBuf::from("/us... | true |
49706a2956e51941aa3536d4a603af0b711024ff | Rust | nakat-t/nlp100 | /q08/src/main.rs | UTF-8 | 456 | 3.125 | 3 | [
"MIT"
] | permissive | use std::char;
fn cipher(s: &str) -> String {
s.chars()
.map(|c| {
if c.is_ascii_alphabetic() && c.is_ascii_lowercase() {
char::from_u32(219 - c as u32).unwrap()
} else {
c
}
})
.collect()
}
fn main() {
let s = "I am a... | true |
70cb1add5f81f335ec78fa78e385c23d9b730c89 | Rust | hardenedapple/playing_with_rust | /src/knapsack_problem/tests/mod.rs | UTF-8 | 5,674 | 3.125 | 3 | [] | no_license | use knapsack_problem::*;
use test_utils::{VectorPermutations,random_vector,MAX_PERMUTATION_SIZE,seeded_rng};
use test_utils::rand::{Rng, Rand};
const MAX_VECTOR_SIZE: usize = 30;
fn alternate_same_set<T: PartialEq + Ord>(left: &mut Vec<T>, right: &mut Vec<T>) -> bool {
left.sort(); right.sort();
left == right
... | true |
3ee82e6c3a1248bc62c564b5832289445867c49b | Rust | Keirua/exercism | /reverse-string/src/lib.rs | UTF-8 | 180 | 2.8125 | 3 | [] | no_license | pub fn reverse(s: &str) -> String {
s.chars().rev().collect()
/*let mut s2:String = String::new();
for c in s.chars().rev() {
s2.push(c);
}
s2*/
}
| true |
67bc32ba0b9c2150e84ab409d0a124914a2f0079 | Rust | gyu-don/cuda_rs | /src/cuda_buildhelper.rs | UTF-8 | 1,136 | 2.796875 | 3 | [] | no_license | use std::env;
use std::path;
#[cfg(windows)]
const NVCC: &'static str = "nvcc.exe";
#[cfg(not(windows))]
const NVCC: &'static str = "nvcc";
pub fn get_cuda_path_from_env() -> Result<String, &'static str> {
let delim;
if cfg!(unix) {
delim = ':';
} else if cfg!(windows) {
delim = ';';
}... | true |
1c8ddf133923b7e212df25e4ceedabd60453faa1 | Rust | pbspbsingh/RLox | /src/parser/mod.rs | UTF-8 | 1,390 | 3.171875 | 3 | [] | no_license | use std::iter::Peekable;
use crate::error::ParsingErr;
use crate::expr::{Expr, infix_op, prefix_op};
use crate::lex::{Token, TokenType};
pub struct Parser<'a, I: Iterator<Item=Token<'a>>> {
tokens: Peekable<I>
}
impl<'a, I: Iterator<Item=Token<'a>>> Parser<'a, I> {
pub fn new(itr: I) -> Self {
Parser... | true |
c4a427f1bbf3b6499e1c99b1319aee5d842bb1e7 | Rust | uzushino/hone | /src/expression.rs | UTF-8 | 12,159 | 2.734375 | 3 | [
"MIT"
] | permissive | use std::fmt;
use std::rc::Rc;
use crate::entity::*;
use crate::query::*;
use crate::types::*;
pub fn parens_<'a, A, B, C>(a: A) -> Rc<dyn 'a + HasValue<B, Output = C>>
where
A: Into<String>,
C: 'a + ToLiteral,
{
Rc::new(Raw(NeedParens::Parens, a.into(), std::marker::PhantomData))
}
pub fn never_<'a, A, ... | true |
87a9db63c67cd79509a4ca858698a4b98af9c7f1 | Rust | dginev/CorTeX | /src/frontend/cached/task_report.rs | UTF-8 | 4,667 | 2.578125 | 3 | [
"MIT"
] | permissive | //! Cache-enabled task reports, delegating to `Backend` for the core reporting logic
use crate::backend::Backend;
use crate::backend::TaskReportOptions;
use crate::frontend::params::ReportParams;
use crate::models::{Corpus, Service};
use redis::Commands;
use rocket::request::Form;
use std::collections::HashMap;
/// Ca... | true |
9c2929252c3425b6b4cf314ab4a2356738c00deb | Rust | SASUKE40/yukino-dev | /query-builder/src/expr.rs | UTF-8 | 2,238 | 3.1875 | 3 | [
"MIT"
] | permissive | use crate::{DatabaseValue, FunctionCall, Ident};
use std::fmt::{Display, Formatter, Result as FmtResult};
pub type ExprBox = Box<Expr>;
#[derive(Clone, Debug)]
pub enum Expr {
Ident(Ident),
Lit(DatabaseValue),
FunctionCall(FunctionCall),
BitInverse(ExprBox),
BitXor(ExprBox, ExprBox),
Mul(ExprB... | true |
9a7ea8e8f93cca0aebe1ef4e80e9231c8109e05e | Rust | fujiapple852/tonic | /tonic/src/body.rs | UTF-8 | 5,280 | 3.203125 | 3 | [
"MIT"
] | permissive | //! HTTP specific body utilities.
//!
//! This module contains traits and helper types to work with http bodies. Most
//! of the types in this module are based around [`http_body::Body`].
use crate::{Error, Status};
use bytes::{Buf, Bytes};
use http_body::Body as HttpBody;
use std::{
fmt,
pin::Pin,
task::{... | true |
7e2f9ed59e823bf63c3906eec546322d1fd78a49 | Rust | Mark-Simulacrum/json-rust | /src/iterators.rs | UTF-8 | 2,650 | 2.703125 | 3 | [
"MIT"
] | permissive | use std::collections::btree_map;
use std::slice;
use std::iter::{ Iterator, DoubleEndedIterator };
use JsonValue;
pub enum Members<'a> {
Some(slice::Iter<'a, JsonValue>),
None
}
pub enum MembersMut<'a> {
Some(slice::IterMut<'a, JsonValue>),
None
}
pub enum Entries<'a> {
Some(btree_map::Iter<'a, S... | true |
73b60295999d26355a39a1c83af2f6b57d4c2bc8 | Rust | rusty-ecma/RESS | /src/tokenizer/unicode.rs | UTF-8 | 1,714 | 2.59375 | 3 | [
"MIT"
] | permissive | #![allow(clippy::all)]
use unicode_xid::UnicodeXID;
/// wrap the `unic_ucd_ident`'s function
/// first short-circuiting around the ascii
/// and other non `CJK` characters
#[inline]
pub(crate) fn is_id_start(c: char) -> bool {
if c >= 'a' && c <= 'z' {
true
} else if c >= 'A' && c <= 'Z' {
true... | true |
be9289229c441e22236226d2d39619de604b5f1e | Rust | akubera/flo | /flo-client-lib/src/async/ops/send_message.rs | UTF-8 | 1,747 | 2.75 | 3 | [] | no_license | use std::fmt::{self, Debug};
use std::io;
use futures::{Sink, Future, Async, Poll};
use futures::sink::Send;
use async::{AsyncConnection, MessageSender, ClientProtocolMessage};
pub struct SendMessage<D: Debug> {
connection: Option<AsyncConnection<D>>,
sender: Send<MessageSender>
}
impl <D: Debug> Debug for ... | true |
f832fb68fac80bc8e444d05a75e9f349c107d029 | Rust | doraneko94/sevendayshpc.rs | /day7/src/magnetic/mag_simd.rs | UTF-8 | 4,262 | 2.515625 | 3 | [
"CC-BY-4.0",
"MIT"
] | permissive | #[cfg(target_arch = "x86")]
use std::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::*;
use rand::distributions::{Distribution, Uniform};
use rand::thread_rng;
const N: usize = 100000;
const IM_YZX: i32 = 64 * 3 + 16 * 0 + 4 * 2 + 1 * 1;
const IM_ZXY: i32 = 64 * 3 + 16 * 1 + 4 * 0 + 1 * 2;
#[deri... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.