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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
af7d9c19a49fd18542a1f22e6a451bc98d930ae5 | Rust | liufoyang/utopia | /consensus/src/lib/bft_signtor.rs | UTF-8 | 2,099 | 2.6875 | 3 | [] | no_license | extern crate crypto;
use crypto::ed25519;
extern crate rustc_hex;
use rustc_hex::{FromHex, ToHex};
extern crate flexi_logger;
use flexi_logger::{Logger, opt_format};
use log::*;
pub struct Bft_Signtor {
private_key:[u8; 64],
public_key:[u8; 32],
seed:String
}
impl Bft_Signtor {
pub fn new() -> Bft_Si... | true |
8b8b36ded58a4eee9e1943812073efeb6e9e635d | Rust | tyan-boot/ordinal | /src/sysinfo.rs | UTF-8 | 5,715 | 2.8125 | 3 | [] | no_license | use anyhow::Result;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::fs;
use tokio::sync::RwLock;
pub mod models;
#[derive(Clone, Default)]
pub struct InnerState {
/// (total, vec<cpus>)
pub cpu: Arc<RwLock<(models::CPUStats, Vec<models::CPUStats>)>>,
/// memory
pub memory: Arc<RwLock<mod... | true |
b59fd153813e9feeede166c6fe6645327ea99096 | Rust | nathanfaucett/rs-input | /src/mouse.rs | UTF-8 | 1,297 | 2.9375 | 3 | [
"MIT"
] | permissive | use glutin::Event;
use vec2;
#[derive(Debug)]
pub struct Mouse {
first: bool,
last: [isize; 2],
focused: bool,
position: [isize; 2],
delta: [isize; 2],
}
impl Mouse {
pub fn new() -> Self {
Mouse {
first: true,
last: [0isize; 2],
focused: true,
... | true |
f61c43cf6bb23b29da9e7c6ec6340674854d796c | Rust | viing937/leetcode | /algorithms/rust/1326.rs | UTF-8 | 638 | 2.765625 | 3 | [
"MIT"
] | permissive | impl Solution {
#[allow(dead_code)]
pub fn min_taps(n: i32, ranges: Vec<i32>) -> i32 {
let n = n as usize;
let inf = n * n;
let mut dp = vec![inf; n + 1];
dp[0] = 0;
(0..=n).for_each(|i| {
let left = 0.max(i as i32 - ranges[i]) as usize;
let righ... | true |
71992bfecf04a0bea6bb32b81d34628358e58b0e | Rust | MrAwesome/ruwi | /src/wpa_cli_initialize.rs | UTF-8 | 2,834 | 2.59375 | 3 | [
"Apache-2.0"
] | permissive | use crate::interface_management::ip_interfaces::LinuxIPInterface;
use crate::prelude::*;
use crate::run_commands::SystemCommandRunner;
use std::thread;
use std::time::Duration;
const WPA_CONNECT_ERROR: &str = "Error initializing wpa_supplicant to use wpa_cli. Specify another scan method with -s, or add the following ... | true |
5799e34693fd29917bfbfb82e28fc548cc01cf83 | Rust | AMEFACTORY/cap | /common/src/index.rs | UTF-8 | 4,104 | 3.046875 | 3 | [] | no_license | use crate::transaction::Event;
use ic_certified_map::{AsHashTree, Hash, HashTree, RbTree};
use ic_kit::Principal;
use sha2::{Digest, Sha256};
use std::collections::BTreeMap;
use std::ptr::NonNull;
/// How many Transaction IDs per page.
pub const PAGE_CAPACITY: usize = 64;
/// Type used for representing the page numbe... | true |
006cbd9fb0c2e3105c124ca12ce98f09466ea24d | Rust | redSlug/PPM-Creator | /ppm_server/src/main.rs | UTF-8 | 5,711 | 2.9375 | 3 | [] | no_license | use std::net::TcpListener;
use std::net::TcpStream;
use std::io::prelude::*;
use std::string::String;
use std::str;
extern crate regex;
use regex::Regex;
use std::fs::File;
use std::io;
use std::path::Path;
use std::io::BufReader;
use std::collections::HashMap;
use std::io::{Error, ErrorKind};
#[derive(PartialEq)]
en... | true |
c1d77df8f2688c76a859d2fb84f0925a643e67f2 | Rust | iFaceless/gic | /src/commiter.rs | UTF-8 | 2,466 | 3.265625 | 3 | [
"MIT"
] | permissive | use crate::command::CommandOption;
use std::process::Command;
/// Committer 维护了用于生成优雅的 Commit Message
/// 所需要的元信息
#[derive(Debug)]
pub struct Committer<'a> {
opt: CommandOption<'a>,
}
impl<'a> Committer<'a> {
pub fn new(opt: CommandOption<'a>) -> Self {
Committer { opt }
}
pub fn run(&self) -... | true |
19699013e88303c0acf5f8d427db5a37a55d363a | Rust | facebookexperimental/MIRAI | /checker/tests/run-pass/unsigned_interval_overflows.rs | UTF-8 | 6,858 | 2.78125 | 3 | [
"MIT"
] | permissive | // Copyright (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//
// Tests arithmetic binary operations that overflow
pub fn tu8_add_overflows(cond: bool) -> u8 {
let a: u8 = if cond { 0xFF } else... | true |
beb4798b2263a2c73d718917c7fda039a5fdf202 | Rust | yssource/Rustonomicon-Source | /adv/learn_arc/src/main.rs | UTF-8 | 619 | 3.671875 | 4 | [] | no_license | use std::thread;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::time;
fn main() {
let data = vec![1, 2, 3, 4]; //创建了一个变量,在堆上分配内存
let idx = Arc::new(AtomicUsize::new(0)); //创建原子变量
let other_idx = idx.clone(); //获取引用
thread::spawn(move || {
other_idx.fetch_add(10, Ordering::SeqCst);... | true |
e1aee932f6fece5616f251d72d751d3c371e354b | Rust | mateovelilla/the_rust_programming_language | /statements_expressions/src/main.rs | UTF-8 | 616 | 3.8125 | 4 | [] | no_license | /**
* is a block that, in this case, evaluates to 4.
* That value gets bound to y as part of the let statement.
* Note the x + 1 line without a semicolon at the end,
* which is unlike most of the lines you’ve seen so far.
* Expressions do not include ending semicolons.
* If you add a semicolon to the end of ... | true |
6b7af6129506b26d9f439bac7ccfa599cdf9c009 | Rust | D3fus/mpd_client | /src/state_changes.rs | UTF-8 | 2,599 | 3.140625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Tools for handling state-change events emitted by MPD.
use futures::stream::Stream;
use tokio::sync::mpsc::UnboundedReceiver;
use std::pin::Pin;
use std::task::{Context, Poll};
pub use crate::errors::StateChangeError;
/// Stream of state change events.
///
/// This is emitted by MPD during the client idle loops... | true |
3a731b93cd4069972e56b764ae9ef8663c83ac1f | Rust | chainzthec/libppm | /src/main.rs | UTF-8 | 2,364 | 2.640625 | 3 | [] | no_license | use std::env;
use ::ppm::entities::image::Image;
use std::path::Path;
fn main(){
let args: Vec<String> = env::args().collect();
let keyword = "yvan".to_string();
if args.len() == 2 && args[1].to_string() == keyword {
println!("==============================");
println!("======= prof.ppm im... | true |
7d8b7479d2a3c08dde1afecfb18c97a7a118d9ae | Rust | tstellanova/pinetime_play | /src/sensor_value_tracker.rs | UTF-8 | 2,141 | 3.34375 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use num_traits::Float;
/// Implements exponential weighted moving average of sensor readings,
/// including exponentially fading minimum and maximum
pub struct SensorValueTracker<T> {
/// recent minimum value (not global minimum)
local_min: T,
/// recent maximum value (not global maximum)
local_max: T,... | true |
f6af9ef06ed266ffce894eb28202869dc5b05274 | Rust | fabianvdW/Scam | /src/types.rs | UTF-8 | 9,374 | 2.671875 | 3 | [] | no_license | use crate::bitboard::*;
// Score
pub type Score = i16;
pub const MATE: Score = 31000;
pub const MATE_IN_MAX: Score = MATE - 999;
pub const fn mate_score(height: u8) -> Score {
-MATE + height as Score
}
pub const fn score_to_tt(score: Score, height: u8) -> Score {
if score > MATE_IN_MAX {
score + hei... | true |
b9272c29b50f5032ce3995ba42a4d88d5b060a47 | Rust | nicholastmosher/fluvio-demo-apps-rust | /cdc-mysql/src/producer/binlog_manager/manager.rs | UTF-8 | 9,627 | 2.5625 | 3 | [
"Apache-2.0"
] | permissive | /// BinLogManager
///
/// File manager listens for changes in the bin-log directory and notifies receiver.
///
use crossbeam_channel::Sender;
use std::cmp;
use std::io::{Error, ErrorKind};
use std::path::{Path, PathBuf};
use std::thread;
use std::time::Duration;
use tracing::{debug, error, instrument, trace};
use supe... | true |
cbfc5a70cd308b44dc5abc2a62c4d6e4a3106a2b | Rust | scottwillmoore/chip16 | /src_old/flags.rs | UTF-8 | 3,807 | 3.34375 | 3 | [
"MIT"
] | permissive | #[derive(Default)]
pub struct Flags {
pub carry: bool,
pub zero: bool,
pub overflow: bool,
pub negative: bool,
}
impl Flags {
pub fn set_on_add(&mut self, a: u16, b: u16) {
let (_, carry) = a.overflowing_add(b);
let (signed_result, overflow) = (a as i16).overflowing_add(b as i16);
... | true |
48c90e6aa3f80e2ddbdf6d518765b1ac3b9159f5 | Rust | BenSuth/video-editor | /video-editor-lib/src/clip.rs | UTF-8 | 904 | 2.71875 | 3 | [
"MIT"
] | permissive | #[derive(Clone)]
pub struct Clip {
pub path: String,
pub inpoint: u64,
pub duration: u64,
pub start: u64,
pub is_video: bool,
pub is_audio: bool,
pub is_render_target: bool,
pub clip: Option<ges::UriClip>
}
impl Clip {
pub fn new(path: &str, inpoint: u64, duration: u64, start: u64, ... | true |
f622674a1f40eceafbc29ea6fb12551e826914c5 | Rust | Abishek0398/AtomicDouble | /src/lib.rs | UTF-8 | 5,148 | 3.4375 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! `AtomicDouble<T>` wrapper type supporting only 128-bit atomics
//!
//! Atomic types provide primitive shared-memory communication between
//! threads, and are the building blocks of other concurrent types.
//! Double width atomics are an essential part of many lock free algorithms to avoid the ABA problem.
//!
//! ... | true |
d47eec8ad85783d5f6bcb3c748ca0583f80b50ca | Rust | survived/mquote | /impl/src/buffer.rs | UTF-8 | 1,071 | 2.6875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use std::iter::FromIterator;
use proc_macro2::TokenTree;
use crate::language::*;
pub struct QTokens {
tokens: Vec<TokenTreeQ>,
}
impl QTokens {
pub fn new() -> Self {
Self { tokens: vec![] }
}
pub fn push(&mut self, token: TokenTreeQ) {
self.tokens.push(token);
}
}
impl IntoIter... | true |
15364ae5fdc0aa9468600cc5a6e50f623d321f22 | Rust | vindvaki/advent-of-code-2018 | /src/bin/day_22.rs | UTF-8 | 6,409 | 3.09375 | 3 | [] | no_license | extern crate regex;
use std::cmp::Reverse;
use std::collections::{BinaryHeap, HashMap};
use std::fmt;
use std::io::Read;
fn main() {
let mut data = String::new();
std::io::stdin().read_to_string(&mut data).unwrap();
let re = regex::Regex::new(
r"^depth: (?P<depth>\d+)\s+target: (?P<target_x>[\d]+)... | true |
77693e17cb7cb920717bb1a74f56c9b1b1909cee | Rust | emabee/rust-dist_tx | /src/tm/xa_transaction_id.rs | UTF-8 | 6,659 | 3.046875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use crate::tm::XaError;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::convert::TryInto;
use std::io::{Read, Write};
use std::iter::repeat;
/// The ID of a distributed transaction, in analogy to the
/// [X/Open XA standard](http://pubs.opengroup.org/onlinepubs/009680699/toc.pdf).
///
#[derive(Clo... | true |
dc6e4e1155db1224e3ac66762c06bc41dc6691a3 | Rust | forkkit/wasmer | /lib/emscripten/src/memory.rs | UTF-8 | 4,988 | 2.609375 | 3 | [
"MIT"
] | permissive | use super::env::get_emscripten_data;
use super::process::abort_with_message;
use libc::{c_int, c_void, memcpy, size_t};
use wasmer_runtime_core::{
units::{Pages, WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE},
vm::Ctx,
};
/// emscripten: _emscripten_memcpy_big
pub fn _emscripten_memcpy_big(ctx: &mut Ctx, dest... | true |
b2ae982b1f583ef9bea622357625e99f562d3192 | Rust | ichyo/ahc003 | /spq/src/remote.rs | UTF-8 | 2,078 | 2.921875 | 3 | [] | no_license | use crate::models::*;
use std::io::{BufRead, Write};
pub struct RemoteEnvironment<R: BufRead, W: Write> {
turn: usize,
reader: R,
writer: W,
next_query: Option<Query>,
}
impl<R: BufRead, W: Write> RemoteEnvironment<R, W> {
pub fn new(reader: R, writer: W) -> Self {
let mut e = RemoteEnviron... | true |
e57c59d73ee20a737208957c1279c4f4b063ab9d | Rust | chromium/chromium | /third_party/rust/cxx/v1/crate/tools/cargo/build.rs | UTF-8 | 2,412 | 2.84375 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"GPL-1.0-or-later",
"LGPL-2.0-or-later",
"BSD-3-Clause"
] | permissive | use std::io::{self, Write};
#[cfg(windows)]
use std::os::windows::fs as windows;
use std::path::Path;
use std::process;
#[cfg(windows)]
use std::{env, fs};
const MISSING: &str = "
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When building `cxx` from a git clone, git's symlink support needs
to be e... | true |
11103d1845995b4b02b0f128c2fd3d380d3c0a92 | Rust | smonv/exercism | /rust/beer-song/src/lib.rs | UTF-8 | 1,136 | 3.65625 | 4 | [] | no_license | pub fn verse(n: u32) -> String {
if n < 1 {
"No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n".to_string()
} else {
let w1 = match n {
2..=u32::MAX => format!("{} bottles", n),
1 => "1 bott... | true |
72a62049b05c9141a660988d57f4da663baa89b7 | Rust | Clemente12/pacman | /src/input.rs | UTF-8 | 2,223 | 3.078125 | 3 | [] | no_license | //!
//! Unbuffered but blocking IO
//!
use termios::{Termios, TCSANOW, ECHO, ICANON, tcsetattr};
use std::io;
use std::io::Read;
use std::io::Write;
use std::sync::mpsc::Sender;
use std::sync::mpsc::Receiver;
use std::thread::Builder as ThreadBuilder;
use std::thread::JoinHandle as ThreadHandle;
pub enum Key
{
... | true |
72a4ae1a5a908e49757b123064382981b7cf8e2e | Rust | roynalnaruto/core | /crates/json-abi/tests/test.rs | UTF-8 | 1,846 | 2.59375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use alloy_json_abi::{AbiItem, AbiJson, Error, Param};
#[test]
fn complex_error() {
let json = r#"{
"inputs": [
{
"internalType": "string",
"name": "reason",
"type": "string"
}
],
"name": "SomeName",
"type": "err... | true |
3a65079337f4bc2c1728643f761077f7fa75da89 | Rust | iqlusioninc/tmkms | /src/key_utils.rs | UTF-8 | 2,993 | 2.75 | 3 | [
"Apache-2.0"
] | permissive | //! Utilities
use std::{
fs::{self, OpenOptions},
io::Write,
os::unix::fs::OpenOptionsExt,
path::Path,
};
use ed25519_dalek as ed25519;
use ed25519_dalek::SECRET_KEY_LENGTH;
use k256::ecdsa;
use rand_core::{OsRng, RngCore};
use subtle_encoding::base64;
use zeroize::Zeroizing;
use crate::{
error::... | true |
9f4802cff95497a15c71bd9a3996318249b33d75 | Rust | MiyamotoTa/actix_web_sample | /src/app/v1/users/repository/user_repository.rs | UTF-8 | 1,486 | 2.625 | 3 | [] | no_license | use async_trait::async_trait;
#[cfg(test)]
use mockall::automock;
use sqlx::{MySql, Pool};
use crate::app::v1::users::model::user::User;
#[cfg_attr(test, automock)]
#[async_trait]
pub(crate) trait UserRepository: Sync {
async fn create(&self, email: &str, name: &str) -> Result<(), sqlx::Error>;
async fn find_... | true |
8a950876c6b5da95643ea42f75b45e7083c3f751 | Rust | royswale/leetcode | /src/bin/valid-palindrome.rs | UTF-8 | 803 | 3.5 | 4 | [
"MIT"
] | permissive | fn main() {
assert_eq!(true, Solution::is_palindrome("A aa".to_string()));
}
struct Solution;
impl Solution {
pub fn is_palindrome(s: String) -> bool {
if s.is_empty() {
return true;
}
let (mut start, mut end) = (0, s.len() - 1);
let s = s.as_bytes();
wh... | true |
d13d2f2bbdb37982cc4b43909593e380be5d0b2e | Rust | hoodie/yaml-pathfinder | /src/lib.rs | UTF-8 | 778 | 2.59375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | pub use yaml_rust::Yaml;
use yaml_rust::YamlLoader;
#[allow(unused_imports)]
use std::{
fmt,
path::Path,
{ffi::OsStr, fs},
};
pub mod error;
pub mod path;
mod pathfinder;
mod util;
pub mod validator;
pub use pathfinder::PathFinder;
/// conviniently just opens and parses a `.yml` file.
pub fn open_yaml<P... | true |
7a6104f6419ab805c65ed1acb3c8f6f9adeebe3a | Rust | neysofu/codegen-rs | /src/field.rs | UTF-8 | 1,047 | 3.1875 | 3 | [
"MIT"
] | permissive | use crate::r#type::Type;
/// Defines a struct field.
#[derive(Debug, Clone)]
pub struct Field {
/// Field name
pub name: String,
/// Field type
pub ty: Type,
/// Field documentation
pub documentation: Vec<String>,
/// Field annotation
pub annotation: Vec<String>,
}
impl Field {
... | true |
99ce63eff6a26b001edff9b72bd44c3556198604 | Rust | binshengliu/exercism-rust | /triangle/src/lib.rs | UTF-8 | 929 | 3.453125 | 3 | [
"MIT"
] | permissive | extern crate num;
use num::Num;
pub struct Triangle<T>
where
T: Num + PartialOrd + Copy,
{
sides: [T; 3],
}
impl<T> Triangle<T>
where
T: Num + PartialOrd + Copy,
{
pub fn build(sides: [T; 3]) -> Result<Triangle<T>, String> {
if Triangle::is_valid(&sides) {
Ok(Triangle { sides })
... | true |
ac89323573d511f434f6d9febce987e3c6073353 | Rust | SuperFluffy/iota_mam | /src/pb3/typ/trint.rs | UTF-8 | 7,397 | 3.25 | 3 | [] | no_license | //! This module describes PB3 `trint3`, `trint6`, `trint9`, `trint18` integer types and relevant commands over them.
use crate::pb3::cmd::{absorb::Absorb, mask::Mask};
use crate::pb3::err::{guard, Err, Result};
use crate::spongos::Spongos;
use crate::trits::{self, TritSlice, TritSliceMut};
/// A helper trait for inte... | true |
0c88f4a90aadc5d663a7ca55654419e259ff587b | Rust | ebkalderon/tq | /src/parser.rs | UTF-8 | 1,295 | 2.59375 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::str::{self, FromStr};
use nom::combinator::all_consuming;
use nom::multi::many0;
use nom::sequence::{delimited, pair, preceded, terminated};
use self::expr::{expr, function_decl};
use self::stmt::stmts;
use crate::ast::{Filter, Module};
mod expr;
mod stmt;
mod tokens;
impl FromStr for Filter {
type Err... | true |
d345ddb8dc6407024b1c89dc858a4e59e6070e24 | Rust | lengyijun/nll2bdd | /biodivine-lib-bdd/src/tutorial/p03_bdd_manipulation.rs | UTF-8 | 3,319 | 4.09375 | 4 | [
"MIT"
] | permissive | //! # Manipulating `Bdd`s idiomatically
//!
//! There are multiple ways of creating `Bdd`s representing complex boolean formulas, each
//! useful in different situations.
//!
//! ## Direct method calls
//!
//! Once you have created the basic formulas, you can combine them using the methods of
//! the `Bdd` struct into ... | true |
38a70019aff130b089fc413c5b88d1e440af934a | Rust | jakearmendariz/multiplayer_lightspeed | /src/session.rs | UTF-8 | 10,231 | 2.71875 | 3 | [] | no_license | use log::{info};
use actix::fut;
use actix::prelude::*;
use actix_broker::BrokerIssue;
use actix_web_actors::ws;
use serde::{Deserialize, Serialize};
use crate::message::{ChatMessage, JoinRoom, LeaveRoom, ListRooms, SendMessage, GetGame, RemovePlayer, ResetGame};
use crate::server::WsChatServer;
use crate::lightspee... | true |
ad5a26025acc7597775789942cb35220567760ea | Rust | raphaelcohn/security-keys-rust | /workspace/security-keys-rust/src/open_pgp/Sex.rs | UTF-8 | 1,616 | 2.828125 | 3 | [
"MIT"
] | permissive | // This file is part of security-keys-rust. 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/raphaelcohn/security-keys-rust/master/COPYRIGHT. No part of security-keys-rust, including this file, may be copied, modified... | true |
9cbb4a1cdc3fce3be198a2b6e4e288a038744047 | Rust | Tembocs/rome | /crates/rome_js_formatter/src/js/expressions/parenthesized_expression.rs | UTF-8 | 4,008 | 2.859375 | 3 | [
"MIT"
] | permissive | use crate::formatter_traits::FormatTokenAndNode;
use crate::utils::{is_simple_expression, FormatPrecedence};
use crate::{
empty_element, format_elements, group_elements, hard_group_elements, FormatElement,
FormatResult, Formatter, ToFormatElement,
};
use rome_js_syntax::{
JsAnyExpression, JsParenthesizedExp... | true |
d33470589dda3f6cda05780b850db42179e16fb4 | Rust | choumarin/rust_snake | /src/main.rs | UTF-8 | 3,522 | 2.828125 | 3 | [] | no_license | mod lib;
use my_snake::{Cell, Collision, Direction, Snake};
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use sdl2::pixels::Color;
use sdl2::render::Canvas;
use sdl2::video::Window;
use std::{thread, time};
fn main() {
let canvas_width = 20_u32;
let canvas_height = 20_u32;
let (mut canvas, mut even... | true |
531bc3c80cb887b5e960770cc83f712ddfba4539 | Rust | tshepang/clap | /examples/tutorial_builder/03_05_default_values.rs | UTF-8 | 334 | 2.8125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use clap::{arg, command};
fn main() {
let matches = command!() // requires `cargo` feature
.arg(arg!([NAME]).default_value("alice"))
.get_matches();
println!(
"NAME: {:?}",
matches
.get_one::<String>("NAME")
.expect("default ensures there is always a val... | true |
c3f8547cf22bc7a78e843a863dacb59313c34705 | Rust | bbqsrc/fruity | /src/core_graphics/geometry/cg_size.rs | UTF-8 | 1,685 | 2.984375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use super::{CGAffineTransform, CGFloat};
/// Width and height values.
///
/// See [documentation](https://developer.apple.com/documentation/coregraphics/cgsize).
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, PartialOrd, PartialEq)]
pub struct CGSize {
/// A height value.
pub height: CGFloat,
/// A width... | true |
1323755c78ec5eb9b66dcd84d82dcb1fd854574b | Rust | edytapawlak/why-cellar-is-safe | /src/ambulance.rs | UTF-8 | 3,538 | 2.71875 | 3 | [] | no_license | use ggez::nalgebra as na;
use ggez::{graphics, Context, GameResult};
use rand;
use rand::Rng;
use crate::moveable::EntityParams;
use crate::moveable::Moveable;
use crate::moveable::Zone;
#[derive(Copy, Clone)]
pub struct Ambulance {
ent_params: EntityParams,
pub destination: na::Point2<f32>,
is_free: bool... | true |
6f5ea16820a57598a5a81f43353fa689c9e6ee85 | Rust | anacrolix/eratosthenes | /rust/actix/src/main.rs | UTF-8 | 2,171 | 3.03125 | 3 | [] | no_license | use actix::prelude::*;
#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
struct Int(u64);
impl Int {
fn multiple_of(&self, div: &Int) -> bool {
self.0 % div.0 == 0
}
fn increment(&mut self) {
self.0 += 1
}
}
impl Message for Int {
type Result = ();
}
struct Link {
div: Opt... | true |
3938e300f906524baf67f68dfdef48df82ade626 | Rust | eranfu/toybox | /tb_ecs/src/system/data.rs | UTF-8 | 4,033 | 2.828125 | 3 | [
"Apache-2.0"
] | permissive | use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
pub(crate) use crate::system::data::access_order::AccessOrder;
use crate::world::{Resource, ResourceId};
use crate::World;
pub trait SystemData<'r> {
/// Fetch SystemData
///
/// # Safety
///
/// The SystemData must meet the reference ... | true |
d20c5809253f527588d5242c5a01d3c3f14ff2f7 | Rust | am0d/rocket-test | /src/controllers/category.rs | UTF-8 | 2,663 | 2.96875 | 3 | [] | no_license | use std::borrow::Cow;
use rocket;
use rocket::request::{FlashMessage, Form};
use std::vec::Vec;
use db;
use models;
use super::context::{IndexTemplateContext, TemplateContext};
use util::*;
use util::response::*;
use models::prelude::*;
/// Returns all the routes defined on this controller
pub fn all_routes() -> Vec<r... | true |
2f0fc7ad7d69cc54274f8041cd37d4530a1975c4 | Rust | EmperDeon/zeus | /src/util/services.rs | UTF-8 | 771 | 2.578125 | 3 | [
"MIT"
] | permissive | use crate::util;
use std::fs::File;
use std::collections::HashMap;
pub fn list(root_path: &String) -> Result<Vec<String>, String> {
let mut names = vec![util::git::MAIN_REPO_NAME.to_owned(), "tests".to_owned()];
names.append(&mut config_list(root_path).unwrap());
Ok(names)
}
fn config_list(root_path: &String) ... | true |
adcee8c76caeb9ae53e7831c1dcdf6f2772172fa | Rust | ok-john/penumbra | /penumbra/src/bin/pcli.rs | UTF-8 | 1,470 | 2.734375 | 3 | [] | no_license | use anyhow::Result;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(
name = "pcli",
about = "The Penumbra command-line interface.",
version = env!("VERGEN_GIT_SEMVER"),
)]
struct Opt {
/// The address of the Tendermint node.
#[structopt(short, long, default_value = "127.0.0.1:266... | true |
e2c81e49d08b88698b3d86e5b1a582c3cac5cca7 | Rust | Wilfred/hhvm | /hphp/hack/src/hackc/emitter/local.rs | UTF-8 | 4,629 | 2.8125 | 3 | [
"MIT",
"PHP-3.01",
"Zend-2.0"
] | permissive | // Copyright (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the "hack" directory of this source tree.
use ffi::Str;
pub type Id = usize;
/// Type of locals as they appear in instructions. Named variables are
/// those appearing in the .... | true |
21d99bdb1e174bbecea07c03c27c777ce7b4bf59 | Rust | ebkalderon/dss-coding-assignment | /src/schema.rs | UTF-8 | 5,547 | 3.109375 | 3 | [] | no_license | //! Types for deserializing DSS API responses.
pub use self::image::{ImageContent, ImageTile};
pub use self::text::{Language, Text, TextContent, TitleKind, Titles};
use fnv::FnvHashMap as HashMap;
use serde::{Deserialize, Serialize};
use url::Url;
use uuid::Uuid;
mod image;
mod text;
/// An API response containing ... | true |
461528a4633ff0bd431fb896c281470548f44452 | Rust | xaviershay/rust-puzzlefighter | /src/human_player.rs | UTF-8 | 11,516 | 3.046875 | 3 | [] | no_license | use board::Board;
use piston_window::*;
use values::*;
use wrapper_types::*;
use std::collections::{HashMap,LinkedList};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
enum InputAction {
AntiClockwise,
Clockwise,
Left,
Right,
Turbo,
DebugLoadBoard,
DebugAttack,
DebugBreaker(Color),... | true |
2eea058c73cf7651e45efe54c8ea45f459ae10f5 | Rust | thedodd/sqlx | /sqlx-core/src/mssql/protocol/type_info.rs | UTF-8 | 20,462 | 2.515625 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use bitflags::bitflags;
use bytes::{Buf, Bytes};
use encoding_rs::Encoding;
use crate::encode::{Encode, IsNull};
use crate::error::Error;
use crate::mssql::Mssql;
bitflags! {
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
pub(crate) struct CollationFlags: u8 {
const IGN... | true |
12d415c995e2a7f77dca82051aa5df0a68a0d321 | Rust | nanne007/naive_p2p | /src/state.rs | UTF-8 | 3,525 | 3.40625 | 3 | [] | no_license | use sha2::{Digest, Sha256};
use std::collections::BTreeMap;
use std::iter::FromIterator;
pub struct NodeState {
data: BTreeMap<u32, Vec<u8>>,
cur_state: Option<(u32, Vec<u8>)>,
}
impl Default for NodeState {
fn default() -> Self {
NodeState::new()
}
}
impl NodeState {
pub fn new() -> NodeS... | true |
e6f566d3cc58b5365129f6fbc3b13f98d1adbccd | Rust | Rustinante/math | /src/traits.rs | UTF-8 | 429 | 2.875 | 3 | [
"Apache-2.0"
] | permissive | //! # General traits
pub mod trait_impl;
pub trait Collecting<E> {
fn collect(&mut self, item: E);
}
pub trait HasDuplicate {
fn has_duplicate(&self) -> bool;
}
pub trait Slicing<I, O> {
fn slice(self, input: I) -> O;
}
pub trait SubsetIndexable<S, Output> {
fn get_set_containing(&self, subset: &S)... | true |
3bf318efcc19b4aa7180c0d68e28bab83822caf2 | Rust | mlange-42/git-igitt | /src/widgets/commit_view.rs | UTF-8 | 4,973 | 2.75 | 3 | [
"MIT"
] | permissive | use crate::app::DiffType;
use crate::util::ctrl_chars::CtrlChars;
use crate::widgets::list::{ListItem, StatefulList};
use git2::Oid;
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::Style;
use tui::widgets::{Block, StatefulWidget, Widget};
#[derive(Default)]
pub struct CommitViewState {
pub content:... | true |
c541b6f5b93b27552065b1680c04497584ddc32e | Rust | CodeSandwich/rust-cardano | /chain-impl-mockchain/src/ledger.rs | UTF-8 | 9,977 | 3.046875 | 3 | [
"MIT"
] | permissive | //! Mockchain ledger. Ledger exists in order to update the
//! current state and verify transactions.
use crate::error::*;
use crate::transaction::*;
use chain_core::property;
use std::collections::HashMap;
/// Basic ledger structure. Ledger is represented as the
/// state of unspent output values, associated with th... | true |
9d2e368db4abaa47c6ea8c6118423f9382c8f02f | Rust | MichaelHe1125/rust-leetcode | /src/p0345_reverse_vowels_of_a_string.rs | UTF-8 | 2,048 | 3.90625 | 4 | [] | no_license | // 345. Reverse Vowels of a String
// Write a function that takes a string as input and reverse only the vowels of a string.
// Example 1:
// Input: "hello"
// Output: "holle"
// Example 2:
// Input: "leetcode"
// Output: "leotcede"
// Note:
// The vowels does not include the letter "y".
pub struct Solution {}
imp... | true |
36abaecb206be83a1629571376ec17f26cd6e96b | Rust | imorph/vector | /lib/vrl/compiler/src/value/target.rs | UTF-8 | 23,249 | 3.75 | 4 | [
"MPL-2.0"
] | permissive | use crate::{Target, Value};
use lookup::{FieldBuf, LookupBuf, SegmentBuf};
use std::collections::BTreeMap;
use std::iter::Peekable;
impl Target for Value {
fn insert(&mut self, path: &LookupBuf, value: Value) -> Result<(), String> {
self.insert_by_path(path, value);
Ok(())
}
fn get(&self, ... | true |
5dffc5408ee4e53b6d4696279509d77714d1d643 | Rust | beltegeuse/rustlight | /src/tools.rs | UTF-8 | 930 | 3.09375 | 3 | [] | no_license | use std;
use std::iter::Iterator;
/// For be able to have range iterators
pub struct StepRangeInt {
start: usize,
end: usize,
step: usize,
}
impl StepRangeInt {
pub fn new(start: usize, end: usize, step: usize) -> StepRangeInt {
StepRangeInt { start, end, step }
}
}
impl Iterator for Step... | true |
3311a1442a492ce7e23fe55b8e7713daa7a42e08 | Rust | githubchry/studyrust | /syntax/src/27refcell.rs | UTF-8 | 5,134 | 3.75 | 4 | [] | no_license | /*
内部可变性(Interior mutability)是 Rust 中的一个设计模式,
它允许你即使在有不可变引用时也可以改变数据,这通常是借用规则所不允许的。
为了改变数据,该模式在数据结构中使用 unsafe 代码来模糊 Rust 通常的可变性和借用规则。
当可以确保代码在运行时会遵守借用规则,即使编译器不能保证的情况,可以选择使用那些运用内部可变性模式的类型。
所涉及的 unsafe 代码将被封装进安全的 API 中,而外部类型仍然是不可变的。
Rust 通过其所有权机制,严格控制拥有和借用关系,来保证程序的安全,并且这种安全是在编译期可计算、可预测的。
但是这种严格的控制,有时也会带来灵活性的丧失,有的场景下甚至还满足... | true |
94ad347f4aa769c7fd96282075d0118856f7b364 | Rust | danbruder/shippy | /src/infra/cli/mod.rs | UTF-8 | 1,026 | 2.609375 | 3 | [] | no_license | use quicli::prelude::*;
use structopt::StructOpt;
use crate::domain::use_cases::{CreateAppInput, CreateAppUseCase};
use crate::infra::{memory::MemoryAppRepo, term::StatefulTable};
use crate::prelude::*;
#[derive(Debug, StructOpt)]
enum Cli {
ListApps,
CreateApp(CreateApp),
}
#[derive(Debug, StructOpt)]
struc... | true |
7c8a0172f43c8c351a1591f57e085213e3bc1a9d | Rust | JamesShoaf/AlgorithmPractice | /binaryTrees/binaryTree/house_robber_iii/src/lib.rs | UTF-8 | 3,040 | 3.546875 | 4 | [] | no_license | /*
The thief has found himself a new place for his thievery again. There is only one entrance to this
area, called the "root." Besides the root, each house has one and only one parent house. After a
tour, the smart thief realized that "all houses in this place forms a binary tree". It will
automatically contact the pol... | true |
cb1dc69417be5860641354b88b1423a6b08ad8bb | Rust | offscale/cargo-make | /src/version_test.rs | UTF-8 | 7,530 | 2.96875 | 3 | [
"LicenseRef-scancode-free-unknown",
"Apache-2.0"
] | permissive | use super::*;
use semver::Version;
#[test]
fn print_notification_simple() {
print_notification("1");
}
#[test]
fn get_version_from_output_empty() {
let version = get_version_from_output("");
assert!(version.is_none());
}
#[test]
fn get_version_from_output_few_args() {
let version = get_version_from_... | true |
b2b52898a4c81e1c25b1ec7af5e4fdf5f63e13de | Rust | Thermatix/cyber_rogue | /src/sys/state.rs | UTF-8 | 6,420 | 2.953125 | 3 | [] | no_license | //! Handles state of the game world
//!
//! Provides the following functionality:
//! - rendering
//! - new maps
//! - new entities
//! - player input
//! - game loop
//! NOTE: Most if not all of these things will be moved into systems
use rltk::{Console, GameState, Rltk, VirtualKeyCode};
use specs::prelude::*;
use s... | true |
f18a97e470697f8b6b5d6649394d4c4b0d9ae5cc | Rust | o1810156/par_quick | /src/main.rs | UTF-8 | 774 | 2.796875 | 3 | [] | no_license | extern crate rand;
extern crate rand_pcg;
use par_quick::quick_sort;
use rand::{Rng, SeedableRng};
use rand::distributions::Standard;
use rand_pcg::Pcg64Mcg;
use std::time::Instant;
fn main() {
let n = 10000000;
let rng = Pcg64Mcg::from_seed([0; 16]);
let mut v = rng.sample_iter(&Standard)
.take(n)... | true |
682e0e641dce6c88c29bb18497ddfb6ee1286c69 | Rust | ggggxiaolong/rCore | /os/src/memory/frame/frame_tracker.rs | UTF-8 | 1,071 | 3.265625 | 3 | [] | no_license | use crate::memory::address::{PhysicalAddress, PhysicalPageNumber};
use crate::memory::frame::allocator::FRAME_ALLOCATOR;
/// 分配出的物理内存页
///
/// # 'Tracker' 是什么?
/// 太长不看
/// > 可以理解为 ['Box'](alloc::boxed::Box), 而区别在于, 其空间不是分配在堆上,
/// > 而是直接在内存中划一片(一个物理页)
///
/// 在我们实现操作系统过程中,会经常遇到 [指定一块内存区域作为某种用处] 的情况.
/// 此时,我们说这块内存可以用... | true |
edd1c04c00e0780a5e0122a5e96468139cbcbe73 | Rust | kenaniah/zero2prod-rocket | /app/tests/subscriptions_test.rs | UTF-8 | 3,378 | 3.375 | 3 | [] | no_license | mod setup;
use db;
use rocket::http::uri::fmt::{Query, UriDisplay};
use rocket::UriDisplayQuery;
#[derive(UriDisplayQuery)]
struct Body<'a> {
name: Option<&'a str>,
email: Option<&'a str>,
}
impl Body<'_> {
/// Returns the struct as an URI-formatted string
pub fn to_uri(&self) -> String {
for... | true |
5c379a511432e87054ec10ca56baf286ba760f0d | Rust | tomc1998/rs-java-parser | /src/parser/formal_parameters.rs | UTF-8 | 2,658 | 2.921875 | 3 | [] | no_license | use lexer::TokenType;
use super::*;
use super::types::parse_type;
use super::variables::parse_variable_modifier;
#[allow(dead_code)]
pub fn parse_formal_parameters(tokens: &mut TokenIter, src: &str) -> ParseRes {
let mut children = vec![assert_term(tokens, src, "(")?];
match tokens.clone().next() {
Som... | true |
67efcee12564de6485329c15e0ab5f93bb3ab732 | Rust | yuyttenhove/slab_mcrt | /src/voronoi_slab.rs | UTF-8 | 5,506 | 2.75 | 3 | [] | no_license | mod voronoi;
mod delaunay;
mod geometry;
mod voronoi_generator;
use crate::vector::Vec2;
use super::Slab;
use voronoi_generator::VoronoiGenerator;
use voronoi::VoronoiGrid;
use delaunay::DelaunayTriangulation;
use rand::{thread_rng, Rng};
#[derive(Copy, Clone, Debug)]
enum NeighbourDirection {
Up,
Right,
... | true |
61a5d009e2d697742b677353ac24ecd9dec448c5 | Rust | isabella232/bongo-2 | /src/start_grammar.rs | UTF-8 | 4,571 | 2.859375 | 3 | [
"Apache-2.0"
] | permissive | use crate::grammar::ElemTypes;
use crate::grammar::{
build, Elem, Grammar, GrammarErrors, Prod, ProdElement, Rule,
};
use crate::utils::{take_only, ToDoc};
use std::marker::PhantomData;
#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Debug)]
pub enum StreamTerminal<T> {
EndOfStream,
Term(T),
}
impl<T> StreamTer... | true |
a76db73cc9b9096838197bffd24adcc4116d99d2 | Rust | isgasho/doku | /doku/tests/json/struct/of_transparent/code.rs | UTF-8 | 531 | 2.953125 | 3 | [
"MIT"
] | permissive | #[derive(Doku)]
pub struct Ty {
/// This is `foo`
foo: Foo,
/// This is `bar`
bar: Bar,
/// This is `zar`
zar: Zar,
}
#[derive(Doku)]
pub struct Foo {
/// This is `f1`
f1: String,
/// This is `f2`
f2: String,
}
#[derive(Doku)]
#[doku(transparent)]
pub struct Bar(BarNested);
... | true |
2e7ffdc0be713f59dffc9aaabb204d4b2b5a4abf | Rust | jDomantas/interpreter | /src/compiler/builtins/mod.rs | UTF-8 | 2,322 | 2.84375 | 3 | [] | no_license | pub mod types {
use symbols::Sym;
pub const FRAC: Sym = Sym(10);
pub const BOOL: Sym = Sym(11);
pub const LIST: Sym = Sym(12);
pub const CHAR: Sym = Sym(13);
pub const STRING: Sym = Sym(14);
pub const INT: Sym = Sym(15);
}
pub mod traits {
use symbols::Sym;
pub const COMPU... | true |
d02047752ab421d8108bf28fa2cc4ba99a8087cf | Rust | mfpiccolo/yaqb | /src/expression/predicates.rs | UTF-8 | 1,997 | 3.109375 | 3 | [] | no_license | use query_builder::*;
use super::{Expression, SelectableExpression, NonAggregate};
use types::Bool;
macro_rules! infix_predicate {
($name:ident, $operator:expr) => {
#[derive(Debug, Clone, Copy)]
pub struct $name<T, U> {
left: T,
right: U,
}
impl<T, U> $name... | true |
cd328db3a2168ffe3f96ee3aa47f332a8cd1aaad | Rust | laamp/rust-learning | /functions/src/main.rs | UTF-8 | 331 | 3.4375 | 3 | [] | no_license | fn main() {
println!("Hello, world!");
another_function(101, 9);
println!(
"Implicit return from other function is {}.",
other_function()
);
}
fn another_function(num1: i32, num2: i32) {
println!("Another function received {} and {}.", num1, num2);
}
fn other_function() -> i32 {
... | true |
da7673f14b705554be24fa21591fe65981850099 | Rust | zydxhs/demo_net | /src/bin/tcp_client.rs | UTF-8 | 821 | 2.703125 | 3 | [
"MIT"
] | permissive | use std::net::{TcpStream, ToSocketAddrs};
use std::str;
use std::{
io::{self, prelude::*, BufReader},
time::Duration,
};
fn main() -> io::Result<()> {
let mut stream = TcpStream::connect_timeout(
&"127.0.0.1:8080".to_socket_addrs().unwrap().next().unwrap(),
Duration::from_secs(1),
)?;
... | true |
7eb13b7b3d107db3810dc8824c01575fc5fe0492 | Rust | krixi/remud | /remud-lib/src/world/action/communicate.rs | UTF-8 | 7,871 | 3.09375 | 3 | [
"MIT"
] | permissive | use bevy_app::EventReader;
use bevy_ecs::prelude::*;
use crate::{
text::Tokenizer,
world::{
action::{get_room_std, into_action, Action},
types::{
player::{Messages, Players},
room::Room,
Location, Named,
},
},
};
pub fn parse_me(player: Entity, t... | true |
62d12a4d7d107381e06a81b3a963836c0c1aab89 | Rust | reformat0r/nae | /examples/tween.rs | UTF-8 | 1,645 | 2.859375 | 3 | [] | no_license | use nae::prelude::*;
use nae::tween::*;
const EASING: [Easing; 10] = [
Easing::Linear,
Easing::InQuad,
Easing::InCubic,
Easing::InExpo,
Easing::OutBack,
Easing::OutSine,
Easing::OutQuart,
Easing::InOutQuint,
Easing::InOutElastic,
Easing::InOutBounce,
];
struct State {
font:... | true |
77d4bd3f6576db3525d4d2d46ca84ee9d7d39a03 | Rust | http-rs/tide | /src/endpoint.rs | UTF-8 | 3,763 | 3.203125 | 3 | [
"MIT",
"LicenseRef-scancode-warranty-disclaimer",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use async_std::future::Future;
use async_std::sync::Arc;
use async_trait::async_trait;
use http_types::Result;
use crate::middleware::Next;
use crate::{Middleware, Request, Response};
/// An HTTP request handler.
///
/// This trait is automatically implemented for `Fn` types, and so is rarely implemented
/// directly... | true |
6c42cfa1662bb0c655cf31575e9764887766ca90 | Rust | audacioustux/exercism_rs | /prime-factors/src/lib.rs | UTF-8 | 302 | 3.140625 | 3 | [] | no_license | pub fn factors(n: u64) -> Vec<u64> {
let mut prime_factors = vec![];
let mut factor: u64 = 2;
let mut val = n;
while val > 1 {
while val % factor == 0 {
prime_factors.push(factor);
val /= factor;
}
factor += 1;
}
prime_factors
}
| true |
ae0eb753ddc105d91bf4df407c335700478f1044 | Rust | ianhuezo/rust_room_gen | /src/structures/universe.rs | UTF-8 | 9,862 | 3.03125 | 3 | [] | no_license | use super::cells::Cell;
use super::globals::*;
use super::rooms::Room;
use rand::prelude::*;
use rand::seq::SliceRandom;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::collections::VecDeque;
use std::fs::*;
use std::io::prelude::*;
use std::rc::Rc;
#[derive(Serialize, Deserialize)]
pub st... | true |
86d08ef9890dc54b8716587ea98b0e8aa79b4e44 | Rust | azriel91/strum | /strum_macros/src/as_ref_str.rs | UTF-8 | 2,676 | 2.703125 | 3 | [
"MIT"
] | permissive | use proc_macro2::TokenStream;
use syn;
use helpers::{unique_attr, extract_attrs, extract_meta, is_disabled};
fn get_arms(ast: &syn::DeriveInput) -> Vec<TokenStream> {
let name = &ast.ident;
let mut arms = Vec::new();
let variants = match ast.data {
syn::Data::Enum(ref v) => &v.variants,
_ ... | true |
4fd78d17c2b3cf68c150d583937a5e8770649d79 | Rust | rnleach/bufr-read | /src/error.rs | UTF-8 | 1,228 | 2.78125 | 3 | [
"Apache-2.0"
] | permissive | #![macro_use]
use eccodes_sys::codes_get_error_message;
use libc;
use std::{error::Error, ffi::CStr, fmt::Display};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BufrErr {
CodesError(libc::c_int),
KeyNulError,
NullPtr,
}
impl Display for BufrErr {
fn fmt(&self, f: &mut std::fmt::Formatter) ->... | true |
0ceccf0f6810f199e64bd29bd70136e8e2c79e99 | Rust | CedarHuang/adrop | /examples/struct.rs | UTF-8 | 433 | 2.90625 | 3 | [
"Apache-2.0"
] | permissive | extern crate adrop;
use adrop::*;
struct Test {}
impl Drop for Test {
fn drop(&mut self) {
println!(
"Dropping HasDrop! ThreadId: {:?}",
std::thread::current().id()
);
}
}
fn main() {
println!("Main ThreadId: {:?}", std::thread::current().id());
let _ = Adrop:... | true |
17abc449388d0e785700e1c217a0d19b7f95e20d | Rust | ives9638/parquet2 | /integration-tests/src/read/primitive.rs | UTF-8 | 4,411 | 2.65625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::convert::TryInto;
use super::utils::ValuesDef;
use parquet::{
encoding::{hybrid_rle::HybridRleDecoder, Encoding},
error::Result,
metadata::ColumnDescriptor,
page::{split_buffer, DataPage, PrimitivePageDict},
read::levels::get_bit_width,
types::NativeType,
};
fn read_buffer_impl<T: Na... | true |
96074ea913dbce656eaf5ff28b8e560c242dd435 | Rust | vpatryshev/rustex | /b1/c17/src/main.rs | UTF-8 | 1,024 | 2.859375 | 3 | [] | no_license | use blog::Post;
fn main() {
let mut post = Post::new();
post.add_text("I ate a salad for lunch today.");
assert_eq!("this is a draft", post.content());
post.request_review();
assert_eq!("Need 2 approvals", post.content());
post.reject();
assert_eq!("this is a draft", post.content());
post.add_text... | true |
db566cbf7abdbb8040508eb0b7c175b534eb6bbe | Rust | althea-net/clarity | /clarity/src/lib.rs | UTF-8 | 2,379 | 2.765625 | 3 | [
"Apache-2.0"
] | permissive | //! # Introduction
//! Clarity is a low-level Ethereum transaction library written in pure Rust.
//!
//! ## Features
//! * Any-endian, 32/64-bit support
//! * Public/private key handling
//! * Transaction signing and verification
//! * ABI enconding for common data types (see `abi::Token` variants)
//!
//! ## Getting s... | true |
7ca0c8a016e179e2661cd374cb5014650485576e | Rust | ralphrecto/advent-of-code | /src/advent2021/day09.rs | UTF-8 | 2,616 | 2.875 | 3 | [] | no_license | use std::collections::HashSet;
use fileutil;
fn get_adjacent(heightmap: &Vec<Vec<i32>>, pos: (usize, usize)) -> HashSet<(usize, usize)> {
let deltas: Vec<(i32, i32)> = vec![(0, 1), (0, -1), (1, 0), (-1, 0)];
let (pos_y, pos_x) = pos;
let adj: HashSet<(usize, usize)> = deltas.iter()
.map(|(dy, dx... | true |
40c6d7320b99ac33071147ac3fa5ef51b65a517b | Rust | jprochazk/typed-lang | /src/parser.rs | UTF-8 | 3,101 | 3.234375 | 3 | [
"MIT"
] | permissive | use crate::ast::*;
use std::borrow::Cow;
macro_rules! op {
($a:ident, $kind:ident) => {
expr!(
$a.span.start..$a.span.end,
UnaryExpr = {
UnaryOp::$kind,
box $a
}
)
};
($a:ident, $b:ident, $kind:ident) => {{
expr!(
$a.span.start..$b.span.end,
BinaryExpr = ... | true |
74a61329c65b1242c910cf82f6b399b055ae8299 | Rust | fhiroki/atcoder | /ABC/abc216/src/bin/a.rs | UTF-8 | 299 | 2.609375 | 3 | [] | no_license | use proconio::{fastout, input};
#[fastout]
fn main() {
input! {
v: f32
}
let x = v.floor();
let y = ((v - x) * 10.0).ceil() as u8;
if y <= 2 {
println!("{}-", x);
} else if y <= 6 {
println!("{}", x);
} else {
println!("{}+", x);
}
}
| true |
fe9234227a813355c46541121007913fa9018198 | Rust | segfo/rust_bareborne_raspberrypi2 | /src/kernel/mod.rs | UTF-8 | 293 | 2.6875 | 3 | [] | no_license | use serial::{getc,write,writec,Writer};
use core::fmt::Write;
#[no_mangle]
pub extern fn kernel_main() {
write("Hello Rust Kernel world!\n");
loop {
let c = getc();
match c{
0x0a|0x0d=>write("\n"),
c => writec(c)
};
}
} | true |
86192f89bd5c088a1f2c5095f3e9ef98b593cfa7 | Rust | OhBonsai/edgedb | /edb/edgeql-rust/src/float.rs | UTF-8 | 652 | 3.15625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | use std::borrow::Cow;
pub fn convert(text: &str) -> Result<f64, Cow<'static, str>> {
let value = text.replace("_", "").parse()
.map_err(|e| format!("can't parse std::float64: {}", e))?;
if value == f64::INFINITY || value == -f64::INFINITY {
return Err("number is out of range for std::float64".... | true |
b671e56a34531fcb3442ea20d22b8898170890f3 | Rust | vain0x/hsp3-ginger | /hsp3-analyzer-mini/ham-core/src/utils/canonical_uri.rs | UTF-8 | 2,642 | 3.328125 | 3 | [
"MIT",
"CC0-1.0"
] | permissive | use lsp_types::Url;
use std::{
env::current_dir,
path::{Path, PathBuf},
};
// 正規化処理を行った後の uniform resource identifier (URI)
//
// 正規化について:
// `a/../b` と `b` のように、等価だが異なる表現を統一的な表現に揃える。
// (シンボリックリンクの展開なども行う。)
//
// ファイルパスの参照先が存在しない場合、
//
// 正規化されていない URL をマップのキーに使ってしまうと、
// 単一のファイルに対して複数のデータが登録できてしまい、不具合の原因になる。... | true |
a1a45093dc7109e1288605fe5cc5534125c043d5 | Rust | isadrtdinov/knapsack | /src/heuristic.rs | UTF-8 | 5,045 | 3.109375 | 3 | [] | no_license | use crate::Item;
mod dynamic {
use crate::Item;
use std::cmp::max;
fn dynamic_table(capacity: u32, items: &Vec::<Item>,
left: usize, right: usize,
) -> (u32, u32, Vec::<u32>, Vec::<u32>)
{
let mut old_table = vec![0; capacity as usize + 1];
let mut left_table = Vec::new();
... | true |
76ebc75ffaf31a937118b3e72468f43749d45589 | Rust | KeAiMianYang/work_repo_training | /Rust/book/10_02_overloading/src/main.rs | UTF-8 | 442 | 3.671875 | 4 | [] | no_license | trait MyBehaviour<T>
{
fn print_with(&self, the_thing: T);
}
struct X;
impl MyBehaviour<&'static str> for X
{
fn print_with(&self, string: &'static str)
{
println!("hello, string! {}", string);
}
}
impl MyBehaviour<i32> for X
{
fn print_with(&self, integer: i32)
{
println!("he... | true |
f5c474617b32742cb1cb25b233d5aa8e3954ba97 | Rust | utensil/hestenes | /src/space.rs | UTF-8 | 528 | 2.765625 | 3 | [
"MIT"
] | permissive | use num::Real;
use dimension::Dimension;
// struct MetricProperties<R: Real> {
// // Making this statically allocated requires usage of
// // `<Self as T>::R` bounds on the `Dimension` trait, which
// // is out of the question, as they'd have to be declared
// // in any function using `Dimension`/`Spac... | true |
ca7113f4e5c8f0838d8c6afe27f411c5a0e5e2c0 | Rust | rebeccacxy/Port-Optimisation-Solution | /libsplinter/src/auth/oauth/error.rs | UTF-8 | 2,171 | 2.765625 | 3 | [
"Apache-2.0"
] | permissive | // Copyright 2018-2020 Cargill Incorporated
//
// 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... | true |
705dc051f1bd148eeb2f55f637276b19ce1b773c | Rust | salimclevy/csml-interpreter | /src/parser/parse_comments.rs | UTF-8 | 2,062 | 2.921875 | 3 | [
"Apache-2.0"
] | permissive | use crate::data::tokens::*;
use nom::{
branch::alt,
bytes::complete::{tag, take_until, take_while},
combinator::opt,
error::ParseError,
multi::many0,
IResult, *,
};
fn comment_single_line<'a, E: ParseError<Span<'a>>>(s: Span<'a>) -> IResult<Span<'a>, Span<'a>, E> {
let (s, _) = tag(INLINE_C... | true |
78aad033092adf7544611f92721f8915e3c8c4c7 | Rust | coolofficials/rv6 | /kernel-rs/src/lock/sleeplock.rs | UTF-8 | 1,690 | 3.140625 | 3 | [
"MIT"
] | permissive | //! Sleeping locks
use core::cell::UnsafeCell;
use super::{Guard, Lock, RawLock, Sleepablelock};
use crate::kernel::kernel_builder;
/// Long-term locks for processes
pub struct RawSleeplock {
/// Process holding lock. `-1` means unlocked.
locked: Sleepablelock<i32>,
/// Name of lock for debugging.
na... | true |
28a689ff10ab712125a956de61b6eab3c15b0f03 | Rust | lotabout/project-euler-rust | /src/bin/p015.rs | UTF-8 | 865 | 3.453125 | 3 | [] | no_license | // p15
//
// This is actually a math problem of counting all
// combinations of the path
//
// The answer is C40/20 = 40!/(20! * 20!)
//
// but the factorial expression is easy to get overflowed.
//
fn gcd(a: u64, b: u64) -> u64 {
let mut x = if a > b {a} else {b};
let mut y = if a > b {b} else {a};
while... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.