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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
489bbacb6bbb057685171f2cf2942648d616d218 | Rust | teppah/aoc-2020 | /src/day_6.rs | UTF-8 | 962 | 3.078125 | 3 | [] | no_license | use std::fs;
use std::collections::HashSet;
use itertools::Itertools;
pub fn custom_customs() {
let lines = fs::read_to_string("inputs/6.txt").unwrap();
let count: usize = lines.split("\n\n")
.map(|entry| {
let chars: HashSet<char> = entry
.chars()
.filter(|... | true |
d4cdc171066cc088fd5bc6734e9853de6dab3723 | Rust | beschaef/rtos | /src/trace.rs | UTF-8 | 10,195 | 3.515625 | 4 | [] | no_license | //! This module is used to trace information. All data is written to port `0x03f8`.
//! It's possible to use five different level of tracing: `Debug`, `Info`, `Warn`, `Error`,
//! `Fatal`, and `None`.
//! If the Trace level is set to `None`, nothing is traced.
//! For easier usage there are different macros for each tr... | true |
4da7444ae63ce7144ce94582d1b2a4b1fe8f74d0 | Rust | paul-schaaf/legal_chess | /src/pieces/queen.rs | UTF-8 | 3,191 | 3.109375 | 3 | [] | no_license | use super::{piece, position, sliding_attacks, sliding_moves};
use crate::{board, chessmove, color};
#[derive(Debug)]
pub struct Queen {
pub color: color::Color,
pub position: position::Position,
}
impl piece::Piece for Queen {
fn color(&self) -> &color::Color {
&self.color
}
fn position(&... | true |
0a39fd9d2ba03f08758b88e4a46dccb2f520bb01 | Rust | mimblewimble/grin | /util/tests/file.rs | UTF-8 | 1,793 | 2.546875 | 3 | [
"Apache-2.0"
] | permissive | // Copyright 2021 The Grin Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agree... | true |
2943db692556f0288c608ca077d1b6aed52cda43 | Rust | Johan-Mi/derivative | /src/types/expr.rs | UTF-8 | 803 | 3.046875 | 3 | [
"Unlicense"
] | permissive | use super::{BinOperation, Number, Var};
use derive_more::Display;
#[derive(Display)]
pub enum Expr {
Number(Number),
Var(Var),
BinOperation(BinOperation),
}
impl Expr {
pub fn derivative(&self, var: &Var) -> Self {
use Expr::{BinOperation, Number, Var};
match self {
Number(... | true |
a91f872d06368fb626434a409ad472ed8ca9d754 | Rust | tweag/nickel | /cli/src/error.rs | UTF-8 | 3,319 | 3.078125 | 3 | [
"MIT"
] | permissive | use nickel_lang_core::{
error::{Diagnostic, Files, IntoDiagnostics},
eval::cache::lazy::CBNCache,
program::Program,
};
pub enum Error {
Program {
program: Program<CBNCache>,
error: nickel_lang_core::error::Error,
},
Io {
error: std::io::Error,
},
#[cfg(feature = ... | true |
ccded213ffac18bbf2d35a2590d95c1ed592262f | Rust | pierangeloc/advent-of-code-20109 | /src/main.rs | UTF-8 | 1,388 | 3.375 | 3 | [] | no_license | use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
use std::cmp::max;
//EX1
fn main() {
let file_name = "/Users/pierangelo.cecchetto/Documents/projects/rust/advent-of-code-20109/resources/ex1-1";
let lines: Vec<String> = lines_from_file(file_name);
//PART 1
let res: i32 = lines... | true |
c9f691e2adfb63d9ad24d1309744dc08c11b41ee | Rust | Happy-Ferret/synapse | /src/torrent/peer/reader.rs | UTF-8 | 20,465 | 2.984375 | 3 | [] | no_license | use std::io::{self, Read, ErrorKind};
use std::mem;
use torrent::peer::Message;
use torrent::Bitfield;
use byteorder::{BigEndian, ReadBytesExt};
use util::{io_err, io_err_val};
pub(super) struct Reader {
state: ReadState,
blocks_read: usize,
}
impl Reader {
pub fn new() -> Reader {
Reader {
... | true |
f6d642947c69b5dc28e3e33345257f270783a8ae | Rust | xxv0/psc | /src/core/traits/ext.rs | UTF-8 | 10,092 | 3.40625 | 3 | [] | no_license | use crate::adaptor::*;
use crate::covert::IntoParser;
use crate::{Msg, Parser};
pub trait ParserExt<S>: Parser<S> {
/// Alternative combinator.
/// The parser `p.or(q)` first applies `p`. If it succeeds, the value of `p` is returned.
/// If `p` *fails without consuming any input*, parser `q` is tried.
... | true |
1914b6876cdf9205e907b5a9618359a0100c56c9 | Rust | convexbrain/Totsu | /solver_rust_conic/totsu/src/matbuild/mod.rs | UTF-8 | 9,511 | 3.046875 | 3 | [
"Unlicense"
] | permissive | use std::ops::{Index, IndexMut, Deref};
use num_traits::{Float, Zero};
use totsu_core::solver::SliceLike;
use totsu_core::{LinAlgEx, MatType, MatOp};
//
/// Matrix builder
///
/// <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
/// <script id="MathJax-script" async src="https://... | true |
6b758763087e7067a847f0ba54cef43097c0b434 | Rust | meisterluk/nuhope | /src/finite_field.rs | UTF-8 | 11,371 | 3.4375 | 3 | [
"BSD-3-Clause"
] | permissive | use std::cmp;
use std::fmt;
use std::usize;
use std::cell::RefCell;
use std::ops::{Add,Sub,Mul,Index,IndexMut};
#[derive(Debug, PartialEq, Eq)]
pub struct FiniteField {
pub size: u32,
}
impl FiniteField {
pub fn new(field_size: u32) -> FiniteField {
FiniteField { size: field_size }
}
pub fn e... | true |
f3cc7008d98deb12e4241d05215c41513154b420 | Rust | x7Gv/qpasswd | /src/main.rs | UTF-8 | 9,866 | 2.71875 | 3 | [] | no_license | pub mod crypt;
pub mod gen;
extern crate base64;
use std::convert::TryInto;
use std::io::BufRead;
use std::thread;
use std::time::{Duration, Instant};
use clap::{App, Arg, AppSettings};
use clipboard::ClipboardContext;
use clipboard::ClipboardProvider;
fn run_encrypt(_data: &str, pass: &str, dbg: bool) {
/*
... | true |
c36c6f35760729173cd6b8f3666165183ddb0e3b | Rust | jievince/nebula-rs | /nebula-fbthrift/nebula-fbthrift-common-v2/src/double.rs | UTF-8 | 1,108 | 2.90625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //
// ref https://stackoverflow.com/questions/39638363/how-can-i-use-a-hashmap-with-f64-as-key-in-rust
//
use std::cmp::Ordering;
#[derive(Clone, Debug)]
pub struct Double(pub f64);
impl Double {
fn canonicalize(&self) -> i64 {
(self.0 * 1024.0 * 1024.0).round() as i64
}
}
impl PartialEq for Double {... | true |
8e8fc9fa28c62563ec9847c235c1d79657f923f9 | Rust | udtrokia/Radiancy | /src/tx/utxo_set.rs | UTF-8 | 3,285 | 2.59375 | 3 | [
"MIT"
] | permissive | use blockchain::blockchain::Blockchain;
use blockchain::block::Block;
use std::collections::HashMap;
use tx::outputs::TXOutputs;
use hex::{encode, decode};
#[derive(Clone)]
pub struct UTXOSet {
pub blockchain: Blockchain
}
impl UTXOSet {
pub fn re_index(self) {
let _db = self.blockchain.state_db.to_ow... | true |
104d0112570bb4be1cb69567ff7b38a16aaf0f7e | Rust | BEDSpEedTEST/tickets.rs | /patreon-proxy/src/patreon/poller.rs | UTF-8 | 2,193 | 2.734375 | 3 | [] | no_license | use super::PledgeResponse;
use super::Tier;
use crate::config::Config;
use crate::database::Tokens;
use std::collections::HashMap;
use std::sync::Arc;
use crate::error::PatreonError;
use log::{debug, error};
use std::time::Duration;
pub struct Poller {
config: Arc<Config>,
client: reqwest::Client,
pub to... | true |
9854393ae5393ebc0bf5a2bd97645a63545d6ec9 | Rust | parkovski/scifiweb | /router/src/handlers.rs | UTF-8 | 4,236 | 2.953125 | 3 | [] | no_license | use std::collections::HashMap;
use std::any::Any;
use std::fmt;
use std::error::Error;
use std::str::FromStr;
use futures::Future;
pub use route_recognizer::Params;
pub type ExtMap = HashMap<String, Box<Any>>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParamErrorKind {
NotFound,
InvalidConversion,
}
#[deriv... | true |
3b535fb9c08e5acab82398721f44f6ff0980ec26 | Rust | bugaevc/ground | /src/net.rs | UTF-8 | 7,981 | 3.078125 | 3 | [] | no_license | use std::{
io::{Error, Result},
net::{SocketAddr, TcpListener, TcpStream},
pin::Pin,
task::{Context, Poll},
};
use futures_core::Stream;
use socket2::SockAddr;
use crate::io::*;
impl Async<TcpListener> {
/// Accepts a TCP connection without blocking.
///
/// This is an async version of [`... | true |
d1c3df2bb087264f5099a6b37a9fdb9d6fd08756 | Rust | Frozen/rustnode1 | /src/crypto/secret_key.rs | UTF-8 | 1,865 | 3.3125 | 3 | [] | no_license | use crate::errors::ConvertError;
use rust_base58::{FromBase58, ToBase58};
use std::cmp::min;
use std::convert::TryFrom;
const SECRET_KEY_SIZE: usize = 32;
#[derive(Debug, Copy, Clone)]
pub struct SecretKey([u8; SECRET_KEY_SIZE]);
impl SecretKey {
fn generate(seed: &[u8]) -> SecretKey {
let mut sk: [u8; S... | true |
d1a64fa363d7370b53389e16c7a79c7cdc875186 | Rust | vigdail/rpn-calc-rs | /src/main.rs | UTF-8 | 263 | 2.609375 | 3 | [] | no_license | use rpn_calc_rs::RPNCalc;
use std::env;
fn main() {
let args: Vec<_> = env::args().skip(1).collect();
let mut calc = RPNCalc::new(args);
match calc.run() {
Ok(answer) => println!("{}", answer),
Err(err) => eprint!("{}", err),
}
}
| true |
36dd449155548f95a4abac7a5f36f9480e1337de | Rust | sharmarajdaksh/the_rust_book | /03_basic_concepts/control_flow.rs | UTF-8 | 1,020 | 4.4375 | 4 | [] | no_license | fn main() {
let number = 3;
if number < 5 { // Condition MUST be a bool. No automatic type conversions :)
println!("true");
} else { // `else if`
println!("false");
}
// if in an expression
let new_number = if number < 5 { number } else { number + 5 };
// Note that types of... | true |
8b733275230aaf07948d2da29f910316cc1394dc | Rust | RazrFalcon/tiny-skia | /src/alpha_runs.rs | UTF-8 | 7,383 | 2.75 | 3 | [
"BSD-3-Clause"
] | permissive | // Copyright 2006 The Android Open Source Project
// Copyright 2020 Yevhenii Reizner
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use alloc::vec;
use alloc::vec::Vec;
use core::convert::TryFrom;
use core::num::NonZeroU16;
use crate::color::AlphaU8;
use cra... | true |
dbab5f1738b66385e0dff803accc354209ff63fa | Rust | lencx/rust-learn-demo | /common_collections/hash_maps/src/main.rs | UTF-8 | 2,054 | 3.53125 | 4 | [] | no_license | use std::collections::HashMap;
fn main() {
create_map();
hashmap_ownership();
read_hashmap_val();
hashmap_update();
}
fn create_map() {
let mut scores = HashMap::new();
scores.insert(String::from("Red"), 10);
scores.insert(String::from("Blue"), 12);
println!("scores: {:?}", scores);
... | true |
497e94c1ade4a270776cacead5982f323afcd66e | Rust | zwhitchcox/leetcode_rs | /src/_0561_array_partition_1.rs | UTF-8 | 288 | 3.21875 | 3 | [
"MIT"
] | permissive | struct Solution;
impl Solution {
fn array_pair_sum(mut nums: Vec<i32>) -> i32 {
nums.sort_unstable();
nums.chunks(2).fold(0, |sum, pair| sum + pair[0])
}
}
#[test]
fn test() {
let nums = vec![1, 4, 3, 2];
assert_eq!(Solution::array_pair_sum(nums), 4);
}
| true |
315d77d98595c431523a70b828cea792f1ce3dad | Rust | nickyc975/RustWebServer | /src/thread_pool.rs | UTF-8 | 3,095 | 3.875 | 4 | [
"MIT"
] | permissive | //! An implementation of M:N job scheduling model.
//!
//! ### Examples
//! ```rust
//! // Define a struct to hold all the needed information for you job.
//! struct MyJob(i32);
//!
//! // Implement Job trait for the struct so that thread pool knowns how to run your job.
//! impl Job for MyJob {
//! fn run(&self) {... | true |
2c62428a17c164f301ef2829cae3bcbbd5a7e7ab | Rust | barakplasma/frawk | /src/runtime/str_impl.rs | UTF-8 | 52,869 | 2.625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | /// Custom string implemenation.
///
/// There is a lot of unsafe code here. Many of the features here can and were implementable in
/// terms of safe code using enums, and various components of the standard library. We moved to
/// this representation because it significanly improved some benchmarks in terms of time a... | true |
fe3df8b8af4e8ad988d3074902de561fcd8afd83 | Rust | teloxide/teloxide | /crates/teloxide-core/src/payloads/add_sticker_to_set.rs | UTF-8 | 1,607 | 2.734375 | 3 | [
"MIT"
] | permissive | //! Generated by `codegen_payloads`, do not edit by hand.
use serde::Serialize;
use crate::types::{InputSticker, MaskPosition, True, UserId};
impl_payload! {
@[multipart = sticker]
/// Use this method to add a new sticker to a set created by the bot. Animated stickers can be added to animated sticker sets an... | true |
35049b71282acc7ecbcd4a0fe760ed0345ef77b2 | Rust | denysvitali/homegate-rs | /src/models/paginated.rs | UTF-8 | 731 | 2.703125 | 3 | [
"MIT"
] | permissive | use serde::{Serialize, Deserialize};
use crate::models::realestate::RealEstate;
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Paginated<T> {
pub from: u32,
pub max_from: u32,
pub results: Vec<T>,
pub size: u32,
pub total: u32,
}
pub fn parse_search_result(s... | true |
fdc45bdfc45dafbe652d40f076833117fec2efc4 | Rust | vvanders/netcode.io | /rust/src/client.rs | UTF-8 | 19,609 | 2.84375 | 3 | [
"BSD-3-Clause"
] | permissive | use common::*;
use error::*;
use channel::{self, Channel};
use packet;
use socket::SocketProvider;
use token::ConnectToken;
use std::net::{SocketAddr, UdpSocket};
use std::io;
#[cfg(test)]
use std::time::Duration;
/// States represented by the client
#[derive(Debug,Clone)]
pub enum State {
/// Connection timed ou... | true |
c8da5511658c1e8122d268f1fbba45f6f755e07c | Rust | senseibaka/advent-of-code | /2015/day01/src/main.rs | UTF-8 | 2,107 | 3.609375 | 4 | [
"Apache-2.0"
] | permissive | use std::fs;
use std::io;
use std::io::BufRead;
use std::io::BufReader;
use std::iter::Iterator;
fn main() {
let input = first_line(file_to_vec("input.txt".to_string()).unwrap());
println!("part 1 answer: {}", determine_floor(&input));
println!("part 2 answer: {}", determine_basement_hit(&input));
}
fn fi... | true |
4f8da233c8cd6a14b73f1c78e077659e5531079b | Rust | dennisss/dacha | /pkg/haystack/src/store/superblock.rs | UTF-8 | 4,061 | 2.65625 | 3 | [
"Apache-2.0"
] | permissive | use crate::types::*;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use common::errors::*;
use crypto::{checksum::crc::CRC32CHasher, hasher::Hasher};
use std::io::{Cursor, Read, Write};
use std::mem::size_of;
const SUPERBLOCK_MAGIC_SIZE: usize = 4;
const CHECKSUM_SIZE: usize = 4;
pub const SUPERBLOCK_SIZ... | true |
5741d432a3c35afcf0671b56b501d46e7c04adb6 | Rust | mvernacc/advent_of_code_2020 | /day19/src/main.rs | UTF-8 | 5,395 | 3.359375 | 3 | [] | no_license | use std::{collections::HashMap, fs};
fn main() {
let text = fs::read_to_string("input.txt").unwrap();
let mut text_parts = text.split("\n\n");
let rule_strings: Vec<&str> = text_parts.next().unwrap().lines().collect();
let messages: Vec<&str> = text_parts.next().unwrap().lines().collect();
let rul... | true |
c2634d9415b817c9367567b9be6f22d385f07981 | Rust | dbrgn/echo-server-rs | /src/main.rs | UTF-8 | 1,417 | 3.28125 | 3 | [] | no_license | //! TCP and UDP Echo Servers.
//!
//! Implementation of [RFC 862](https://tools.ietf.org/html/rfc862)
extern crate clap;
use std::process;
mod tcp;
/// An EchoServer instance must be able to handle clients.
pub trait EchoServer {
fn start(&self, host: &str, port: u16) -> Result<(), String>;
}
fn main() {
... | true |
07b22e0ede8dc8afd76606f8a5481d81a82fe21f | Rust | rafalpiotrowski/emerald-vault | /src/convert/json/address.rs | UTF-8 | 2,878 | 3.25 | 3 | [
"Apache-2.0"
] | permissive | use crate::blockchain::ethereum::EthereumAddress;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use std::str::FromStr;
impl<'de> Deserialize<'de> for EthereumAddress {
fn deserialize<D>(deserializer: D) -> Result<EthereumAddress, D::Error>
where
D: Deserializer<'de>,
{
... | true |
b9642bbbb6dd048e6e538a813fdb1df70a1f66f6 | Rust | lunacookies/advent_of_code_2019 | /src/bin/day_1.rs | UTF-8 | 628 | 3.078125 | 3 | [
"ISC"
] | permissive | use std::str::FromStr;
const INPUT: &str = include_str!("day_1_input");
fn calc_shallow_fuel(mass: u32) -> u32 {
let fuel = i64::from(mass) / 3 - 2;
if fuel > 0 {
fuel as u32
} else {
0
}
}
fn calc_fuel(mass: u32) -> u32 {
let mut iter_fuel = mass;
let mut total_fuel = 0;
... | true |
1b499a4b0363fecff55025ee8c72169c04c62147 | Rust | themasch/rust-raytracer | /src/objects/quad.rs | UTF-8 | 1,279 | 3.109375 | 3 | [] | no_license | use cgmath::prelude::*;
use objects::WorldPosition;
use raycast::Ray;
use types::Point;
pub struct Quad {
size: Point,
}
impl Quad {
pub fn intersects(&self, ray: &Ray, position: &WorldPosition) -> bool {
let pmin = position.translate(Point::new(0.0, 0.0, 0.0));
let pmax = position.translate(s... | true |
0fe0c45163e462e868c5287a854cc1c33937ad4d | Rust | gnoliyil/fuchsia | /src/virtualization/bin/vmm/device/virtio_block/src/copy_on_write_backend.rs | UTF-8 | 9,378 | 2.875 | 3 | [
"BSD-2-Clause"
] | permissive | // Copyright 2022 The Fuchsia 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 {
crate::backend::{BlockBackend, DeviceAttrs, Request, Sector},
anyhow::{anyhow, Error},
async_trait::async_trait,
futures::future::try... | true |
2435458f34f7f28b5d494072d251917e8fa4e5e9 | Rust | lordmauve/rustybasic | /src/lib.rs | UTF-8 | 2,356 | 3.21875 | 3 | [] | no_license | use std::collections::HashMap;
use std::error::Error;
use std::fmt;
// use std::Vec;
#[derive(Debug)]
pub struct SyntaxError {
msg: String
}
impl SyntaxError {
fn new(msg: &str, lineno: usize) -> SyntaxError {
SyntaxError { msg: format!("{} at line {}", msg, lineno) }
}
}
impl fmt::Display for Sy... | true |
8c73197f3c9faf3a2298abbc4253e3d42882b3ed | Rust | gabrielesvelto/api-daemon | /third-party/standback/src/lib.rs | UTF-8 | 18,776 | 2.734375 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #![allow(non_camel_case_types, unstable_name_collisions)]
#![cfg_attr(not(feature = "std"), no_std)]
//! Standback backports a number of methods, structs, and macros that have been
//! stabilized in the Rust standard library since 1.31.0. This allows crate
//! authors to depend on Standback rather than forcing downstr... | true |
5ba50bfbcbfb034313bf79d60443555b9e5b35f9 | Rust | sagiegurari/duckscript | /duckscript_sdk/src/sdk/std/collections/range/mod_test.rs | UTF-8 | 2,803 | 2.53125 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-free-unknown"
] | permissive | use super::*;
use crate::test;
use crate::test::CommandValidation;
use crate::utils::state::get_handles_sub_state;
#[test]
fn common_functions() {
test::test_common_command_functions(create(""));
}
#[test]
fn run_no_args() {
test::run_script_and_error(vec![create("")], "out = range", "out");
}
#[test]
fn run... | true |
061d42fa0e4a8421923aa6128a9ac102968a4195 | Rust | oyundev/may_minihttp | /src/response.rs | UTF-8 | 3,590 | 2.921875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use std::io;
use bytes::BytesMut;
pub struct Response<'a> {
headers: [&'static str; 16],
headers_len: usize,
status_message: StatusMessage,
body: Body,
rsp_buf: &'a mut BytesMut,
}
enum Body {
SMsg(&'static str),
VMsg(Vec<u8>),
DMsg,
}
struct StatusMessage {
code: &'static str,
... | true |
1fd14679a659144c864e24423bdd2269f8268ee9 | Rust | InfinityByTen/AoC-2020 | /day01/day1.rs | UTF-8 | 1,980 | 3.5625 | 4 | [] | no_license | use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;
fn get_puzzle() -> Option<Vec<i32>> {
if let Ok(lines) = read_lines("./input_1_d1.txt") {
let mut numbers = Vec::new();
for line in lines {
if let Ok(num_str) = line {
if let Ok(num) = num_str.parse::<... | true |
174970ae08110447ddc18ec07df36152a78fa9ee | Rust | BearGuy/saito | /src/transaction.rs | UTF-8 | 3,074 | 2.8125 | 3 | [] | no_license |
// 0 = normal
// 1 = golden ticket
// 2 = fee transaction
// 3 = rebroadcasting
// 4 = VIP rebroadcast
// 5 = floating coinbase / golden chunk
#[derive(Serialize, Deserialize, PartialEq, Debug, Copy, Clone)]
pub enum TransactionType {
Base,
GoldenTicket,
Fee,
Rebroadcast,
VIP,
GoldenChunk,
}
#[derive(Ser... | true |
79c6f616a67fe57df82e98c12cf8e74d1452687e | Rust | barnex/brilliance-ray-tracer | /brilliance/src/math/util.rs | UTF-8 | 630 | 3.546875 | 4 | [] | no_license | pub use std::f64::consts::PI;
use std::ops::Mul;
/// One degree in radians.
/// E.g.: `90.0 * DEG` is a right angle.
pub const DEG: f64 = PI / 180.0;
pub const INF: f64 = 1.0 / 0.0;
pub const INF32: f32 = 1.0 / 0.0;
// TODO: min, max on PartialOrd, handling NaN !>, !<
/// Return x if > 0, 0 otherwise.
///
/// u... | true |
cd069c9fbbe146f6faecc6ba4fccc9138b97285f | Rust | CircArgs/Elements-of-Programming-in-Rust | /src/problem_6_1/mod.rs | UTF-8 | 4,208 | 4.125 | 4 | [] | no_license | //! EoPI pg 68 Interconvert Strings and Integers
//! In this problem, you are to irnplement methods that take a string representing an integer and retum
//! the corresponding integer, and vice versa. Your code should handle negative integers. You cannot
//! use library functions like int in Python.
//! Implement an int... | true |
1aa94951e924c5f63249573931e06dfd82257048 | Rust | rust-lang/rustlings | /exercises/enums/enums3.rs | UTF-8 | 1,723 | 3.6875 | 4 | [
"MIT"
] | permissive | // enums3.rs
//
// Address all the TODOs to make the tests pass!
//
// Execute `rustlings hint enums3` or use the `hint` watch subcommand for a
// hint.
// I AM NOT DONE
enum Message {
// TODO: implement the message variant types based on their usage below
}
struct Point {
x: u8,
y: u8,
}
struct State {... | true |
39c7ffa94ebf4d5631a2d7ff0b483d52484dd96e | Rust | SkoltechRobotics/rosbag-rs | /src/error.rs | UTF-8 | 1,924 | 3.171875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use crate::cursor::OutOfBounds;
use std::convert::From;
use std::fmt;
/// The error type for ROS bag file reading and parsing.
#[derive(Debug)]
pub enum Error {
/// Invalid headed.
InvalidHeader,
/// Invalid record.
InvalidRecord,
/// Encountered unsupported version in record.
UnsupportedVersio... | true |
daab969d1678eefa0a4e8acc1fa46773b3e4d3e0 | Rust | Builditluc/smokey | /src/settings.rs | UTF-8 | 11,514 | 2.828125 | 3 | [
"MIT"
] | permissive | use crate::storage;
use crate::utils::{count_lines_from_path, StatefulList};
use crate::vec_of_strings;
use phf;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::PathBuf;
use tui::style::Color;
pub const SCRIPT_SIGN: &'static str = "#!";
pub fn is_script(text: &str) -> bool {
if text.len() <... | true |
c89c40994acd24c6056c2f5da5fdd6ae22a6f8eb | Rust | ArakiTakaki/sandbox-node | /sandbox-wasm/rust/src/lib.rs | UTF-8 | 1,168 | 3.15625 | 3 | [] | no_license | extern crate rulinalg;
extern crate wasm_bindgen;
use rulinalg::matrix::Matrix;
use rulinalg::vector::Vector;
// use std::io::{stdout, Write};
use wasm_bindgen::prelude::*;
mod game;
use game::Game;
fn main() {
// let out = stdout();
// let mut out = out.lock();
// Create a 2x2 matrix:
//
let a =... | true |
9732e5c45a21036f9afb418dff9134b1d536d5dd | Rust | DomBlack/advent-of-code-2017 | /day-18/src/instructions.rs | UTF-8 | 3,503 | 3.640625 | 4 | [
"MIT"
] | permissive | use std::str::FromStr;
use std::collections::HashMap;
/// Parses an input string into a vector of instructions
pub fn parse(s: &str) -> Vec<Instruction> {
s.trim().lines().map(| l | l.parse().unwrap()).collect()
}
/// A register name
pub type RegisterName = char;
/// The registers collection
pub type Registers =... | true |
175e63fe6bcdb3f1d8cc2066ecf52d420c78f6cf | Rust | scottschroeder/shirley-raytracing-rs | /src/raytracer/material/texture/mod.rs | UTF-8 | 2,171 | 3.015625 | 3 | [
"MIT"
] | permissive | use crate::core::{Color, Point};
pub mod checker;
pub mod image_texture;
pub mod loader;
pub mod solid;
pub trait Texture: std::fmt::Debug {
fn value(&self, u: f64, v: f64, p: &Point) -> Color;
}
// impl<S> Texture for std::sync::Arc<S>
// where
// S: Texture + std::fmt::Debug,
// {
// fn value(&self, u:... | true |
ee52f051390d73feee25f735725e6ff64a0ae17f | Rust | yavrib/adventofcode2018 | /src/solutions/first.rs | UTF-8 | 1,175 | 3.328125 | 3 | [] | no_license | use super::super::utils::file::reader;
use std::num::ParseIntError;
pub fn solve() {
let changes_in_frequency: String = reader("src/solutions/data.txt");
let changes: Vec<&str> = changes_in_frequency.split("\n").collect();
let new_values: Vec<(&Fn(i64, i64) -> i64, Result<i64, ParseIntError>)> = changes
.i... | true |
25b962901fd4e878dbfa36d69e67a0fa1c98c373 | Rust | bashhack/cyprust | /learn-rust-by-writing-linked-lists/src/first.rs | UTF-8 | 395 | 3.234375 | 3 | [] | no_license | /**
* Functional definition (a la Haskell) of a linked list,
* a recursive definition expressed as a sum type (a type
* that can have different values which may be different
* types, Rust refers to these types as `enum`s)
*
* Ex. List a = Empty | Elem a (List a)
*
* We can write Rust's version of this functiona... | true |
c63defb09d7528aefdfa521036268897ebc35efe | Rust | evq/embedded-graphics | /tinytga/src/header.rs | UTF-8 | 3,337 | 3.0625 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use crate::parse_error::ParseError;
use nom::*;
/// TGA footer length in bytes
pub const HEADER_LEN: usize = 18;
/// Image type
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum ImageType {
/// Image contains no pixel data
Empty = 0,
/// Color mapped image
ColorMapped = 1,
/// Truecolor image
... | true |
6a560e44f709691b58da24836a8427c94a0c4db1 | Rust | dantepippi/yewprint | /yewprint-doc/build.rs | UTF-8 | 1,661 | 2.53125 | 3 | [
"MIT"
] | permissive | use std::env;
use std::ffi::OsString;
use std::fs;
use std::path::Path;
use syntect::highlighting::{Theme, ThemeSet};
use syntect::parsing::SyntaxSet;
fn main() {
let syntax_set = SyntaxSet::load_defaults_newlines();
let theme_set = ThemeSet::load_defaults();
let out_dir = env::var_os("OUT_DIR").unwrap();
... | true |
464d583cbe7220de09c48356d41ce1a0e27bef2f | Rust | alex-snezhko/dirman | /src/main.rs | UTF-8 | 46,398 | 3.046875 | 3 | [] | no_license | use std::env;
use std::fs::{self, Metadata};
use std::os::windows::prelude::*;
use std::ffi::OsString;
use std::path::PathBuf;
use std::io;
use std::ops::{Add, AddAssign, Sub};
use std::cmp::{PartialEq, max, min};
use std::cell::RefCell;
use std::rc::Rc;
use console::Term;
use crossterm::event::{self, Event};
use chron... | true |
3b2e77f068aa54eaf3d429478e72ce7ff4aaf13d | Rust | MwlLj/rust-data-structure | /bplus-tree/src/file/kv/create.rs | UTF-8 | 4,597 | 3 | 3 | [] | no_license | use super::*;
use std::fs;
use std::path;
use std::io::SeekFrom;
use std::io::prelude::*;
impl FileIndex {
pub fn create_inner<'a>(name: &'a str, opt: CreateOption) -> Result<(), &'a str> {
/*
** 1. 判断name文件是否存在, 如果不存在, 则创建
** 2. 写入基本数据到文件头
*/
let mut indexFile... | true |
26fb8925ae5b90630d8e850a26c46a2f90e0aa16 | Rust | caravel-lang/caravel | /src/symbol_table.rs | UTF-8 | 815 | 3.234375 | 3 | [] | no_license | use crate::types::Type;
use std::collections::HashMap;
pub struct SymbolTable {
parent: Option<Box<Self>>,
symbols: HashMap<String, Type>,
}
impl SymbolTable {
pub fn new(parent: Option<Box<Self>>) -> Self {
SymbolTable {
parent,
symbols: HashMap::new(),
}
}
pub fn set(&mut self, identi... | true |
413758c831fdcf9f527965030cfa158baffcaadd | Rust | benblank/cryptopals-rust | /src/exercise7.rs | UTF-8 | 444 | 2.59375 | 3 | [] | no_license | use crate::rijndael::decrypt_block;
use std::fs;
const KEY: &[u8] = b"YELLOW SUBMARINE";
pub fn run_and_print() {
let message = base64::decode(&fs::read_to_string("7.txt").unwrap().replace("\n", "")).unwrap();
let decrypted = message
.chunks_exact(16)
.map(|chunk| decrypt_block(&chunk, KEY).un... | true |
413f26ff4d3c52ab753c883dc328a262a8d56776 | Rust | Minimal-C/RollcageExtractor | /Rollcage-File-Parser/src/file_formats/gt.rs | UTF-8 | 5,243 | 2.765625 | 3 | [
"MIT"
] | permissive | use std::convert::TryInto;
use nom::{IResult, bytes::complete::tag, number::complete::le_u32};
const GT_MAGIC: &[u8; 4] = &[0x47, 0x54, 0x32, 0x30]; // "GT20"
pub struct GTHeader {
pub gt_signature: [u8;4],
pub gt_uncompressed_size: u32,
pub gt_overlap: u32, // Overlap for in-situ decompression
pub gt_skip: ... | true |
c8e3e0a8f6f006e1c262d212fb1c8454ea2b322d | Rust | likr/atcoder | /typical90/src/bin/060.rs | UTF-8 | 1,529 | 2.625 | 3 | [] | no_license | use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;
use superslice::*;
#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usiz... | true |
b58e75b091617b4ecfabe7c41cc84986450e48c6 | Rust | pum-purum-pum-pum/asteroids2.0 | /telemetry/src/plot.rs | UTF-8 | 3,723 | 2.8125 | 3 | [
"Apache-2.0"
] | permissive | use common::*;
use gfx_h::Canvas;
use red::GL;
use std::collections::{HashMap, VecDeque};
use std::time::{Duration, Instant};
#[derive(Debug, Clone)]
pub struct Plot<T: Copy> {
plot_data: PlotData,
duration: Duration,
queue: VecDeque<(Instant, T)>,
}
#[derive(Debug, Clone)]
pub struct PlotData {
pub c... | true |
4aa664b4ac8b8e0db9f6187686e7bc591ce53e90 | Rust | dave-andersen/quick-xml | /tests/serde_rename_roundtrip.rs | UTF-8 | 3,839 | 3.0625 | 3 | [
"MIT"
] | permissive | #![cfg(feature = "serialize")]
extern crate quick_xml;
extern crate serde;
use quick_xml::{de::from_str, se::to_string};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Nested {
#[serde(rename="A")]
a: ItemA,
#[serde(rename="B")]
b: ItemB,
#[serde(r... | true |
bdc3b82fd6baff738c1eab856cf7a40d5030d8ee | Rust | athei/fritzlogger | /src/backend/csv.rs | UTF-8 | 4,143 | 2.859375 | 3 | [
"Apache-2.0"
] | permissive | use super::Backend;
use crate::device::Device;
use crate::errors::*;
use crate::settings;
use config::Value;
use csv::{Writer, WriterBuilder};
use serde::{Deserialize, Serialize};
use std::fs::{File, OpenOptions};
use std::time::Duration;
#[derive(Deserialize, Serialize)]
pub struct Settings {
out_dir: String,
}... | true |
82e855fd22024b6f38e242bbf101f1e98927f8e0 | Rust | tykel/retrogram | /src/arch/sm83/types.rs | UTF-8 | 2,860 | 2.828125 | 3 | [] | no_license | //! Types used in modeling the SM83
use std::str;
use crate::{memory, ast, reg, analysis};
/// Enumeration of all architectural GBZ80 registers.
///
/// Couple things to note:
///
/// * We don't consider register pairs (e.g. BC, DE, HL)
/// * F isn't considered special here
/// * SP has been treated as a registe... | true |
2aef79cae380924afa673a9fa989256b1d454c70 | Rust | jamesthesnake/rg3d | /src/scene/mod.rs | UTF-8 | 13,275 | 2.734375 | 3 | [
"MIT"
] | permissive | #![warn(missing_docs)]
//! Contains all structures and methods to create and manage scenes.
//!
//! Scene is container for graph nodes, animations and physics.
pub mod base;
pub mod camera;
pub mod graph;
pub mod light;
pub mod mesh;
pub mod node;
pub mod particle_system;
pub mod sprite;
pub mod transform;
use crate... | true |
579e756ae00f106727252b1758d23c455db0c999 | Rust | PistonDevelopers/conrod | /conrod_core/src/widget/bordered_rectangle.rs | UTF-8 | 6,904 | 3.046875 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! The `BorderedRectangle` widget and related items.
use widget;
use widget::triangles::Triangle;
use {
Borderable, Color, Colorable, Dimensions, Point, Positionable, Rect, Scalar, Sizeable, Widget,
};
/// A filled rectangle widget that may or may not have some border.
#[derive(Copy, Clone, Debug, WidgetCommon_)... | true |
d0230aeaee69d2d2efdc31a0103f5200032846d5 | Rust | JARVIS-AI/war | /crates/war-cli/src/command/dsav/mod.rs | UTF-8 | 625 | 2.59375 | 3 | [] | no_license | use failure::Error;
use structopt::StructOpt;
mod decode;
mod edit;
mod encode;
#[derive(StructOpt)]
pub enum Command {
/// Convert a .dsav file to a human-readable JSON file
Decode(decode::Command),
/// Write a .dsav file with the save from a decoded JSON file
Encode(encode::Command),
/// Interac... | true |
db742f939dad6923149be1b4ea13fb01e3dc9e3a | Rust | abedegno/top-collectd | /src/lib.rs | UTF-8 | 5,593 | 2.65625 | 3 | [
"MIT"
] | permissive | use std::io;
use std::io::BufRead;
use std::fs;
use std::fs::File;
use glob::glob;
use sysconf::raw::sysconf;
use sysconf::raw::SysconfVariable;
use std::time::Duration;
use shuteye::sleep;
extern crate shuteye;
extern crate glob;
extern crate sysconf;
#[macro_use]extern crate collectd_plugin;
#[macro_use]extern crate... | true |
37c681eb055cfe59e4e016ca3ab82f54f95149ef | Rust | minmul117/baekjoon | /1001/1001.rs | UTF-8 | 326 | 3.0625 | 3 | [] | no_license | use std::io;
fn main(){
let mut numbers = String::new();
io::stdin().read_line(&mut numbers).expect("Failed to read inputs");
let mut iter = numbers.split_whitespace();
let a = iter.next().unwrap();
let b = iter.next().unwrap();
println!("{}", a.parse::<i32>().unwrap() - b.parse::<i32>().unwrap... | true |
d9ada8c38200a9446e586006e9ce30aa6a96e1b2 | Rust | qdequele/toku | /src/stopwords/urd.rs | UTF-8 | 10,680 | 2.65625 | 3 | [] | no_license | use once_cell::sync::Lazy;
use std::collections::HashSet;
/// اُردُو (Urdu)
pub static STOPWORDS_URD: Lazy<HashSet<&'static str>> = Lazy::new(|| {
[
"آئی",
"آئے",
"آج",
"آخر",
"آخرکبر",
"آدهی",
"آًب",
"آٹھ",
"آیب",
"اة",
"اخبزت... | true |
7542e7e23a37614b79fee58ae09e596187048d4e | Rust | squeeko/Rust-Symbolic-Math | /src/expand.rs | UTF-8 | 10,543 | 2.859375 | 3 | [
"BSD-2-Clause"
] | permissive | use crate::modify::Modify;
use crate::modify::Modify::{Changed, Same};
use crate::{Add, Exp, ExprMod, ExprPtr};
use crate::{Expr, Symbol};
use crate::{Ln, Mul};
use std::collections::VecDeque;
use std::env::var;
use std::ops::Deref;
use std::process::exit;
// exp(x + y) => exp(x) * exp(y)
pub(crate) fn expand_exp_sum(... | true |
ef5a0c0a8d746bfaa43b1b5821cae555f842ba15 | Rust | richardanaya/posterity_ukiyoe | /ukiyoe/src/point.rs | UTF-8 | 146 | 3.046875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #[derive(Copy, Clone, Debug)]
pub struct Point {
pub x: f64,
pub y: f64
}
impl Point {
pub fn new() -> Self {
Point { x: 0.0, y: 0.0 }
}
}
| true |
6d56e51bb2d947586e5008b7aa216d747438234a | Rust | drone-os/drone-core | /src/fib/future.rs | UTF-8 | 3,053 | 2.96875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | use crate::fib;
use crate::fib::Fiber;
use crate::sync::spsc::oneshot::{channel, Canceled, Receiver};
use crate::thr::prelude::*;
use core::future::Future;
use core::intrinsics::unreachable;
use core::pin::Pin;
use core::task::{Context, Poll};
/// A future that resolves on completion of the fiber from another thread.
... | true |
e73368c8692adeabbe190b668476e053110be84c | Rust | michaelkyu/sourmash | /src/index/linear.rs | UTF-8 | 5,555 | 2.671875 | 3 | [
"LicenseRef-scancode-public-domain",
"BSD-3-Clause"
] | permissive | use std::fs::File;
use std::io::{BufReader, Read};
use std::mem;
use std::path::Path;
use std::path::PathBuf;
use std::rc::Rc;
use failure::Error;
use lazy_init::Lazy;
use serde_derive::{Deserialize, Serialize};
use typed_builder::TypedBuilder;
use crate::index::storage::{FSStorage, ReadData, Storage, StorageInfo, To... | true |
44d5363abbaebcc8dddc7d03dae1f4e8608c230f | Rust | huwb/learningrust | /src/svgwriter.rs | UTF-8 | 1,757 | 3.375 | 3 | [] | no_license | // from http://keepcalmandlearnrust.com/2017/03/polymorphism-in-rust-enum-vs-trait-struct/
use std::fmt;
trait SvgWriter {
fn write(&self);
}
struct Point {
x: u32,
y: u32,
}
impl Point {
fn new(x: u32, y: u32) -> Point {
Point { x, y }
}
}
impl fmt::Display for Point {
fn fmt(&self,... | true |
756e14a9082d18b4e6830634696321a96a551384 | Rust | ngoldbaum/project_euler | /problem011/src/main.rs | UTF-8 | 3,481 | 3.234375 | 3 | [
"MIT"
] | permissive | use ndarray::{Array, Ix2};
use std::fs::File;
use std::io::prelude::*;
struct Sequence((u64, u64, u64, u64));
impl Sequence {
fn prod(&self) -> u64 {
(self.0).0 * (self.0).1 * (self.0).2 * (self.0).3
}
}
fn main() -> Result<(), Box<std::error::Error>> {
let filename = "data.txt";
let content... | true |
d712d5bd309a16c2a5b47c3bb7867dc426c11f29 | Rust | Terkwood/BUGOUT | /gateway/src/redis_io/stream/unacknowledged.rs | UTF-8 | 4,598 | 2.5625 | 3 | [
"MIT"
] | permissive | use super::xack::XAck;
use super::StreamData;
use log::error;
use redis_streams::XReadEntryId;
pub struct Unacknowledged {
move_made: Vec<XReadEntryId>,
history_provided: Vec<XReadEntryId>,
sync_reply: Vec<XReadEntryId>,
wait_for_opponent: Vec<XReadEntryId>,
game_ready: Vec<XReadEntryId>,
priva... | true |
6a4ddf2105864e605a4bf54362a185a2683be845 | Rust | 0xA537FD/binance-rs-async | /src/util.rs | UTF-8 | 2,254 | 2.875 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"MIT",
"Apache-2.0"
] | permissive | use crate::errors::*;
use chrono::Utc;
use serde_json::Value;
use std::collections::BTreeMap;
pub fn build_request(parameters: &BTreeMap<String, String>) -> String {
let mut request = String::new();
for (key, value) in parameters {
let param = format!("{}={}&", key, value);
request.push_str(par... | true |
733a2a91c4994fa6c3318344d5289004c701de9c | Rust | unknownue/leetcode.rs | /src/p00xx/p42.rs | UTF-8 | 6,283 | 3.71875 | 4 | [
"MIT"
] | permissive | //!
//! Trapping Rain Water
//!
//! https://leetcode.com/problems/trapping-rain-water/
//!
//! Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
//!
//! 
//! trait to help providers to ... | true |
3ee946643e4c7a3d8b1081101d2871a2929424c0 | Rust | samsamai/arcs-wasm-experiment | /src/keyboard_event_args.rs | UTF-8 | 4,073 | 3.453125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | #[allow(unused_macros)]
use std::{fmt::Debug, str::FromStr};
#[derive(Debug, Copy, Clone, PartialEq, Default)]
pub struct KeyboardEventArgs {
pub shift_pressed: bool,
pub control_pressed: bool,
/// The semantic meaning of the key currently being pressed, if there is
/// one.
pub key: Option<VirtualKeyCode>,
... | true |
e88a621ac892ef130f17238a8c68be1b27a1a55e | Rust | 18616378431/myCode | /rust/test5-40/src/main.rs | UTF-8 | 948 | 3.71875 | 4 | [] | no_license | //结构体中的引用成员标注生命周期参数
/// 生命周期省略规则
/// 1.每个参数位置上省略的生命周期参数都将成为不同的生命周期参数'a 'b 'c
/// 2.如果只有一个输入参数,则其生命周期参数将分配给返回值
/// 3.如果存在多个输入生命周期位置,但包含&self或&mut self,则self的生命周期参数将分配给输出
///
#[derive(Debug)]
struct Foo<'a> {
part : &'a str,
}
impl<'a> Foo<'a> {
fn split_first(s : &'a str) -> &'a str {
s.split(',').next... | true |
6e82ebb9d118e2860329ffb8013ab46738851cc2 | Rust | tomoyuki-nakabayashi/Rustemu86 | /debug/src/lib.rs | UTF-8 | 629 | 2.78125 | 3 | [
"Apache-2.0"
] | permissive | use std::fmt;
use std::io;
pub enum DebugMode {
Disabled,
PerCycleDump,
Interactive,
}
impl DebugMode {
pub fn do_cycle_end_action<T>(&self, cpu: &T)
where T: fmt::Display
{
match self {
DebugMode::Disabled => (),
DebugMode::PerCycleDump => {
... | true |
a5a30ec525b468a79c6b870904cd01e3ee345896 | Rust | vpraid/intoif | /src/lib.rs | UTF-8 | 3,171 | 4.125 | 4 | [
"MIT"
] | permissive | //! This library provides two convenient traits that allow you to convert values into `Option` or `Result`
//! based on the provided predicate. It is somewhat similar to the boolinator crate, except you don't
//! need to create a boolean - the predicate will do it for you. This can be useful e.g. when writing a
//! lon... | true |
77f4bd29e38b1fab156e5e3bf1363925bf868ac5 | Rust | pk0912/RustPractice | /functions/src/main.rs | UTF-8 | 1,061 | 4.15625 | 4 | [] | no_license | fn main() {
another_function(5, 6);
let x = 14;
let y = {
let x = 3;
println!("The value of x is: {}", x);
x + 1 // an expression does not include ending semicolons; adding a semicolon will make it a statement
};
println!("The value of x is: {}", x);
println!("The value... | true |
87913ec972d38e84c7231f320a23dec6c1776a22 | Rust | 0x6c7862/sandpit | /src/main.rs | UTF-8 | 1,780 | 2.59375 | 3 | [
"Unlicense"
] | permissive | //! sandpit is a toy sandboxed Linux application
#![warn(box_pointers,
fat_ptr_transmutes,
missing_debug_implementations,
trivial_casts,
unsafe_code,
unstable_features,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
unused_resu... | true |
3799650932256307ab38ad1316f15686511a1650 | Rust | wzhd/rotor | /src/host/mod.rs | UTF-8 | 1,787 | 2.546875 | 3 | [] | no_license | use crate::types::os::OS;
use std::io;
mod user;
pub use self::user::user;
pub use self::user::HostUsersConf;
use crate::effect::Runnable;
use crate::PrResult;
use std::fmt;
use std::str::FromStr;
pub trait ConfigureUser {
fn list_users(&self) -> Vec<&str>;
fn configure(&self, user_name: &str) -> PrResult<()>... | true |
3cd5af05285b029720d746c3f758f2738ff2086e | Rust | bdrobinson/monkey | /src/object/environment.rs | UTF-8 | 1,156 | 3.234375 | 3 | [] | no_license | use crate::object::Object;
use core::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
#[derive(Debug)]
pub struct Environment<'a> {
map: HashMap<String, Rc<Object<'a>>>,
outer: Option<Rc<RefCell<Environment<'a>>>>,
}
impl<'a> Default for Environment<'a> {
fn default() -> Self {
Envir... | true |
bffe16fe4742a55e8f076828fe9a4e3d48dc68bb | Rust | netcrack/luminance-rs | /luminance/src/tessellation.rs | UTF-8 | 3,567 | 3.921875 | 4 | [
"BSD-3-Clause"
] | permissive | //! Tessellation features.
//!
//! # Tessellation mode
//!
//! Tessellation is geometric information. Currently, several kind of tessellation is supported:
//!
//! - *point clouds*;
//! - *lines*;
//! - *line strips*;
//! - *triangles*;
//! - *triangle fans*;
//! - *triangle strips*.
//!
//! Those kind of tessellation ... | true |
6ec4aa75beafa979a1d632a6ac2d8dbfcfef7700 | Rust | GiantPlantsSociety/diamond | /whisper/src/bin/whisper-resize.rs | UTF-8 | 2,734 | 2.859375 | 3 | [
"MIT"
] | permissive | use std::error::Error;
use std::path::PathBuf;
use std::process::exit;
use std::time::{SystemTime, UNIX_EPOCH};
use structopt::StructOpt;
use whisper::aggregation::AggregationMethod;
use whisper::error;
use whisper::resize::resize;
use whisper::retention::Retention;
#[derive(Debug, StructOpt)]
#[structopt(name = "whi... | true |
0af1f6e92754be8f497cca8355f6c16b79b52a4e | Rust | sugyan/leetcode | /others/june-leetcoding-challenge-2021/week-1/3765/lib.rs | UTF-8 | 1,562 | 3.328125 | 3 | [] | no_license | pub struct Solution;
impl Solution {
pub fn is_interleave(s1: String, s2: String, s3: String) -> bool {
if s1.len() + s2.len() != s3.len() {
return false;
}
let s1 = s1.as_bytes();
let s2 = s2.as_bytes();
let s3 = s3.as_bytes();
let mut dp = vec![false; s... | true |
23c5d3eb08fadaa0e556c1a2265688dbd3b22d58 | Rust | arronmabrey/differential-dataflow | /src/trace/layers/hashed.rs | UTF-8 | 16,104 | 3.15625 | 3 | [
"MIT"
] | permissive | //! Implementation using ordered keys with hashes and robin hood hashing.
use std::default::Default;
use timely_sort::Unsigned;
use ::hashable::{Hashable, HashOrdered};
use super::{Trie, Cursor, Builder, MergeBuilder, TupleBuilder};
const MINIMUM_SHIFT : usize = 4;
const BLOAT_FACTOR : f64 = 1.1;
// I would like t... | true |
d72c05990b9bd1cdc5e96173161ca1f86972db56 | Rust | przprz/exercism-rust | /raindrops/src/main.rs | UTF-8 | 263 | 3.125 | 3 | [] | no_license | fn main() {
let n = 12;
let divides_by =
|divisors: Vec<usize>| divisors.iter().all(|d: &usize| n % d == 0);
println!("{}", divides_by(vec![1, 3]));
println!("{}", divides_by(vec![1, 5]));
println!("{}", divides_by(vec![1, 4, 6]));
} | true |
535383caee1b4c671cb50ed6faf51aae5e5f2820 | Rust | seandewar/challenge-solutions | /leetcode/hard/longest-valid-parentheses.rs | UTF-8 | 2,852 | 3.421875 | 3 | [] | no_license | // https://leetcode.com/problems/longest-valid-parentheses
//
// This solution is non-obvious, but:
//
// By getting the start index of the outer brace upon finding a ')', we can calculate the length of
// the valid parentheses sub-string enclosed by the outer braces that ends at this ')'.
//
// The best way to underst... | true |
8cb2611d2949e9a8cb4121719307d8a5aa909855 | Rust | jkelleyrtp/reducer | /src/mock.rs | UTF-8 | 3,390 | 2.8125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | #![cfg(test)]
#![allow(clippy::unit_arg)]
use crate::dispatcher::Dispatcher;
use crate::reactor::Reactor;
use crate::reducer::Reducer;
use proptest_derive::Arbitrary;
use std::{cell::RefCell, marker::PhantomData};
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub(crate) enum Never {}
pub(crate) type Mock<T> = TaggedM... | true |
238176f1acb1a79780a16c403c626fc49b18f70f | Rust | qeebr/rust-like | /src/character/backpack.rs | UTF-8 | 4,157 | 3.375 | 3 | [] | no_license | use super::item::*;
pub const BACKPACK_SIZE: usize = 20;
pub struct Backpack {
pub items: Vec<Item>,
}
impl Backpack {
pub fn new() -> Backpack {
let items = vec![
get_free(),
get_free(),
get_free(),
get_free(),
get_free(),
get_f... | true |
b7c9b66438d1928353f1feaa1da02cc29c055e67 | Rust | vijfhoek/trillium | /cookies/src/cookies_conn_ext.rs | UTF-8 | 1,066 | 2.90625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | use cookie::{Cookie, CookieJar};
use trillium::Conn;
/**
Extension trait adding cookie capacities to [`Conn`].
Important: The [`CookiesHandler`](crate::CookiesHandler) must be
called before any of these functions can be called on a conn.
*/
pub trait CookiesConnExt {
/// adds a cookie to the cookie jar and return... | true |
3906844848113f9f8cf9c0cb505324ea0ccdfa5b | Rust | dpogretskiy/ggez-animation-showcase | /src/physics/quad_tree.rs | UTF-8 | 4,623 | 3.03125 | 3 | [] | no_license | use super::*;
use std::borrow::BorrowMut;
use std::cell::RefCell;
use std::iter;
pub trait Positioned {
fn to_rect(&self) -> Rect;
}
pub struct QuadTree<'a, T: 'a> {
level: usize,
bounds: Rect,
objects: Vec<&'a T>,
nodes: Option<RefCell<Box<[QuadTree<'a, T>; 4]>>>,
}
impl<'a, T> QuadTree<'a, T>
... | true |
d07d7b33f8ae6e32dbaee88a3e8bca3847ecb71b | Rust | PsichiX/emergent | /src/evaluators/sum.rs | UTF-8 | 1,423 | 3.1875 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Calculates sum of sub-consideratiosn scores.
use crate::{consideration::*, Scalar};
/// Gives sum of all considerations scores.
///
/// # Example
/// ```
/// use emergent::prelude::*;
///
/// let consideration = EvaluatorSum::default()
/// .consideration(40.0)
/// .consideration(2.0);
/// assert_eq!(consi... | true |
c7280f7dc63af51869b29913a136388a263e907b | Rust | seungha-kim/rust-practice | /src/collections/string.rs | UTF-8 | 480 | 3.1875 | 3 | [] | no_license | #[cfg(test)]
mod tests {
#[test]
fn string_plus() {
let s1 = String::from("Hello, ");
let s2 = String::from("world!");
// s1에 & 붙이면 에러: Add trait가 `&self`에 대해서 구현되어 있지 않음
let _s3 = s1 + &s2; // note s1 has been moved here and can no longer be used
// https://learning.oreilly.... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.