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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
4dbf9dd617587b7b56ab886fcc59a298e5abcf7c | Rust | Rodrigodd/space-invaders-emu | /src/space_invaders.rs | UTF-8 | 14,594 | 2.546875 | 3 | [
"MIT"
] | permissive | use std::sync::mpsc::{channel, Sender};
use intel8080::{interpreter, IODevices, Memory};
use std::{io::Cursor, thread};
use winit::{
dpi::{LogicalPosition, LogicalSize, PhysicalSize},
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
event_loop::{ControlFlow, EventLoop},
};
use p... | true |
5596f21f8be639906e2a1f39207b01fb55d79548 | Rust | superspindel/CANUST | /src/canust.rs | UTF-8 | 24,900 | 2.796875 | 3 | [] | no_license | #![allow(dead_code)]
use stm32f0x::{GPIOA, RCC, CAN, gpioa, can, GPIOB, gpiof};
use core::ops::Deref;
use core::any::{Any};
/*
Implementation for the Canust API
*/
/*
Receive next incomming message from a specified fifo queue, current implementation has two queues.
*/
macro_rules! receive_fifo {
($FUNCNAME:id... | true |
b968d6e534cbf4c37a4471959fd8d2d3412af2b6 | Rust | RustCrypto/password-hashes | /balloon-hash/src/params.rs | UTF-8 | 3,462 | 3.171875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! Balloon password hash parameters.
use crate::{Error, Result};
use core::num::NonZeroU32;
#[cfg(feature = "password-hash")]
use password_hash::{errors::InvalidValue, ParamsString, PasswordHash};
/// Balloon password hash parameters.
///
/// These are parameters which can be encoded into a PHC hash string.
#[deriv... | true |
870b61bdd02ffe1a419d6dcf43f71c1ef8f3d14c | Rust | watchexec/command-group | /src/tokio/child/unix.rs | UTF-8 | 3,309 | 2.84375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use std::{
convert::TryInto,
io::{Error, ErrorKind, Result},
os::unix::process::ExitStatusExt,
process::ExitStatus,
};
use nix::{
errno::Errno,
libc,
sys::{
signal::{killpg, Signal},
wait::WaitPidFlag,
},
unistd::Pid,
};
use tokio::{
process::{Child, ChildStderr, ChildStdin, ChildStdout},
task::spawn_bl... | true |
14eb02d2c1ebe16dc12c38d3dab818fbabefedbc | Rust | gcastellov/brute-force | /src/main.rs | UTF-8 | 2,784 | 3.15625 | 3 | [
"MIT"
] | permissive | use crate::core::Dictionary;
use context::execution::AppParameters;
use std::fs::*;
use std::ops::Deref;
use std::{env, io::Write};
mod context;
mod core;
enum ExecutionType {
NonVerbose,
Verbose,
}
impl ExecutionType {
fn get_event(&self) -> Box<dyn Fn(u64, String)> {
match self {
Exe... | true |
33652e29181bf7bf5499be6f0a33b718881ba786 | Rust | engvik/rust-book-examples | /ch7/restaurant_part_3/src/lib.rs | UTF-8 | 698 | 2.65625 | 3 | [] | no_license | mod front_of_house {
pub mod hosting {
pub fn add_to_waitlist() {}
}
}
use crate::front_of_house::hosting;
// use self::front_of_house::hosting;
// use crate::front_of_house::hosting::add_to_waitlist;
// pub use crate::front_of_house::hosting;
pub fn eat_at_restaurant() {
hosting::add_to_waitlist(... | true |
3d506cccc7581f78de98a0d10f1f406bc4285ec0 | Rust | openshift/cincinnati | /prometheus-query/src/v1/queries/instant.rs | UTF-8 | 1,282 | 2.8125 | 3 | [
"Apache-2.0"
] | permissive | //! Impelement instant queries
use super::*;
use anyhow::Result as Fallible;
use reqwest;
use std::time::Duration;
pub static INSTANT_QUERY_PATH_SUFFIX: &str = "/api/v1/query";
impl Client {
/// Sends the given query to the remote API, given an optional `time` and timeout.SystemTime
///
/// The `time` is... | true |
0b123b3e34a3c1ce372debb5888bbc24b7cee6ff | Rust | mah-shee/agc017 | /src/bin/a.rs | UTF-8 | 544 | 2.546875 | 3 | [] | no_license | #[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
input! {
n: usize,
p: usize,
a: [usize; n],
}
let mut count_even = 0;
for i in a.iter() {
if i % 2 == 0 {
count_even += 1;
}
... | true |
ddee88c3e181d5559ae234755f2a06d8cdb0fe87 | Rust | dojobrothers/dojo-2016-07-29 | /dojo/src/lib.rs | UTF-8 | 2,234 | 3.5 | 4 | [] | no_license | pub fn fac(n: i32) -> i32 {
if n <= 1 {
1
} else {
n * fac(n-1)
}
}
pub fn i2rm(n:i32) -> String {
if n >= 1000 {
"M".to_string() + &i2rm(n - 1000)
} else if n >= 900 {
"CM".to_string() + &i2rm(n - 900)
} else if n >= 500 {
"D".to_string() + &i2rm(n - 500)
} else if n >= 400 {
... | true |
8f2f0106116c21ab5b0f77508a0bcab8b9280926 | Rust | JonnyWalker81/rusty_lamp | /rusty_lamp_lib/src/lib.rs | UTF-8 | 3,226 | 2.625 | 3 | [
"MIT"
] | permissive | #![feature(conservative_impl_trait)]
pub mod parser;
pub mod generator;
use parser::lexer::Lexer;
use parser::parser::Parser;
use parser::program::Program;
use generator::resolver::Resolver;
use generator::generator::{ Generator, Generate};
use generator::cpp_generator::{CppGenerator};
use generator::java_generator::{... | true |
c85044d9b864b81c1598a3220103c60b20769526 | Rust | csherratt/BillBe | /src/rtc.rs | UTF-8 | 4,632 | 2.828125 | 3 | [] | no_license | use {Memory, Error, Mode, BusDescription};
pub struct Rtc {
addr: u8,
uip: u8,
daylight_saving_time: bool,
hours_24_or_12: bool,
binary_or_bcd: bool,
update_ended_interrupt_enabled: bool,
alarm_interrupt_enabled: bool,
periodic_interrupt_enabled: bool,
set_command: bool,
update_... | true |
2707bfc43d80fa1afe9e9ca95bcb5dd478141ddb | Rust | 27factorial/threader | /src/thread_pool/mod.rs | UTF-8 | 10,351 | 3.140625 | 3 | [
"MIT"
] | permissive | mod task;
mod worker;
use crate::executor::Executor;
use crossbeam::{
deque::{Injector, Stealer, Worker},
queue::ArrayQueue,
};
use futures::Future;
use std::{
io,
sync::{atomic::Ordering, Arc},
thread::JoinHandle,
};
use task::Task;
/// An executor which distributes tasks across multiple threads ... | true |
3ba2be1c0f6a8ad9a7a7c0250dc90d3e1cab5ced | Rust | frullis/timeyApi2 | /src/models/projects.rs | UTF-8 | 1,906 | 2.671875 | 3 | [] | no_license | use diesel;
use diesel::prelude::*;
use diesel::mysql::MysqlConnection;
use crate::schema::projects;
//use crate::models::Projects;
extern crate chrono;
use self::chrono::{DateTime, Duration, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
use serde::{Serialize, Serializer, Deserialize, Deserializer, de::Error};
... | true |
7e3e0aa097518135a94fa603ccb4847509f225d4 | Rust | echochamber/rust_spin_wheel | /src/main.rs | UTF-8 | 2,157 | 2.53125 | 3 | [
"MIT"
] | permissive | extern crate piston_window;
extern crate piston;
extern crate rand;
extern crate sdl2_window;
use std::cell::RefCell;
use std::env::current_exe;
use piston_window::*;
use std::f64::consts::PI;
use sdl2_window::Sdl2Window;
// mod wheel;
mod game_grid;
mod game;
mod models;
mod display;
fn main() {
// Tinker with ... | true |
fe0fe0d1376fee79bc9114dd10589e58ade04ad7 | Rust | oxidecomputer/third-party-api-clients | /docusign/src/envelope_workflow_definition.rs | UTF-8 | 7,659 | 2.859375 | 3 | [
"MIT"
] | permissive | use crate::Client;
use crate::ClientResult;
pub struct EnvelopeWorkflowDefinition {
pub client: Client,
}
impl EnvelopeWorkflowDefinition {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
EnvelopeWorkflowDefinition { client }
}
/**
* Gets an envelope's workflow definition.
*... | true |
3f34844d518be3f1d835ec1fc6ca84fca331823b | Rust | Cannonbait/RustRacer | /src/shapes/sphere.rs | UTF-8 | 2,433 | 3.09375 | 3 | [] | no_license | use crate::model::color::*;
use crate::model::ray::*;
use crate::model::shape::*;
use crate::model::types::*;
use crate::model::vector::*;
use std::f64::consts;
pub struct Sphere {
pub pos: Vector3f,
pub radius: Fu,
pub color: Color,
}
impl Shape for Sphere {
fn intersects(&self, origin: &Vector3f, di... | true |
c7706c7e9672e7b34510fa4204e419c115962027 | Rust | Atul9/canrun_rs | /canrun/src/goals/cmp/gt.rs | UTF-8 | 1,351 | 3.265625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use crate::goals::assert_2;
use crate::goals::Goal;
use crate::value::IntoVal;
use crate::DomainType;
use std::fmt::Debug;
/// Ensure that one value is greater than another.
///
/// # Example:
/// ```
/// use canrun::{unify, util, var, all, Goal};
/// use canrun::example::I32;
/// use canrun::cmp::gt;
///
/// let (x, ... | true |
c38a1b093bfa27477516e3f64fd73b1618b5eaa2 | Rust | Uinelj/zelkow-rs | /zilean/src/database.rs | UTF-8 | 4,654 | 3.84375 | 4 | [] | no_license | //! Handles a Redis database and enables storing and loading champions from it.
//!
//! # Examples
//!
//! # Storing
//!
//! ```rust,ignore
//! use self::zilean::database::*;
//! use self::zilean::champion::*;
//! let db = Database::new("redis://127.0.0.1/".to_string());
//! let champion = Champion::new(10);
//!
//! //... | true |
59ffa39722c23cbc2ada3042795ef7949dde8c35 | Rust | hannobraun/vndf-2016 | /source/rust/vndf/src/client/keyboard.rs | UTF-8 | 3,356 | 2.984375 | 3 | [
"CC0-1.0"
] | permissive | use glutin::Event;
use glutin::Event::{KeyboardInput};
use glutin::VirtualKeyCode;
use glutin::ElementState::{Pressed,Released};
use rand::{random,thread_rng, sample};
use client::graphics::camera::Camera;
use client::interface::{
Frame,
InputEvent,
};
use shared::game::data::{ManeuverData};
/// Keyboard Inpu... | true |
78b7cdc07ecd044b9060d60cfd04dee707bb9fd3 | Rust | cwboden/.dotfiles | /games/dcg_render/src/card/location_card.rs | UTF-8 | 3,315 | 3.328125 | 3 | [
"MIT"
] | permissive | use sdl2::pixels::Color;
use sdl2::rect::Rect;
use sdl2::render::{Texture, TextureCreator, TextureQuery};
use sdl2::ttf::Font;
use serde::Deserialize;
// handle the annoying Rect i32
macro_rules! rect(
($x:expr, $y:expr, $w:expr, $h:expr) => (
Rect::new($x as i32, $y as i32, $w as u32, $h as u32)
)
);
... | true |
2582ad197209c10d167e41831954c55473672a56 | Rust | isgasho/velcro | /velcro/examples/fibonacci.rs | UTF-8 | 320 | 3.390625 | 3 | [
"MIT"
] | permissive | use velcro::vec;
// A (very!) inefficient implementation of Fibonacci sequence
fn fib(a: u64, b: u64, len: usize) -> Vec<u64> {
if len == 0 {
vec![]
} else {
vec![a, ..fib(b, a + b, len - 1)]
}
}
fn main() {
let fibs = fib(1, 1, 7);
assert_eq!(fibs, vec![1, 1, 2, 3, 5, 8, 13]);
}
| true |
cf223a3fbfdd615083daab1495f34b1524efef74 | Rust | d6y/d2d | /src/main.rs | UTF-8 | 2,441 | 3.421875 | 3 | [] | no_license | use std::fs::File;
use std::i32;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
struct Settings {
#[structopt(short, long, default_value = "2.0")]
factor: f32,
#[structopt(parse(from_os_str))]
input: PathBuf,
}
fn main() -> Result<(), ... | true |
b63ff03d16f65a5866833ba36b32e8fe28aed3b9 | Rust | SourangshuGhosh/v3 | /languages/rust/exercises/concept/options/src/lib.rs | UTF-8 | 271 | 2.875 | 3 | [
"MIT"
] | permissive | pub struct Player {
pub health: u32,
pub mana: Option<u32>,
pub level: u32,
}
impl Player {
pub fn revive(&self) -> Option<Player> {
unimplemented!()
}
pub fn fireball(&mut self, mana_cost: u32) -> u32 {
unimplemented!()
}
}
| true |
53a8f9ae43da5d8b27530b8ccb31a1e1aba83f77 | Rust | lkighy/rust-learning-notes | /Rust 程序设计语言学习笔记/结构体/定义并实例化结构体.rs | UTF-8 | 1,725 | 3.6875 | 4 | [] | no_license |
// 定义
struct User {
username: String,
email: String,
sign_in_count: u64,
active: bool,
}
fn main() {
// 结构体实例
let user = User{
username: String::from("daming"),
email: String::from("1000000@123.com"),
active: true,
sign_in_count: 1,
};
... | true |
c2248a970f50f730d84b2dc7d804058ad5592e96 | Rust | eliovir/rust-examples | /design_pattern-decorator.rs | UTF-8 | 2,166 | 3.765625 | 4 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-other-permissive",
"Apache-2.0",
"LicenseRef-scancode-public-domain"
] | permissive | //! Design pattern: Decorator
//!
//! Implement in Rust the design pattern found in Wikipedia (PHP example).
//!
//! Tested with rust-1.3.0
//!
//! @see <http://fr.wikipedia.org/wiki/D%C3%A9corateur_%28patron_de_conception%29#Exemple_en_PHP>
//!
//! @author Eliovir <http://github.com/~eliovir>
//!
//! @license MIT lice... | true |
72e237b00470666269f232824fb63a49eb2a1293 | Rust | wasmerio/wasmer | /lib/virtual-io/src/waker.rs | UTF-8 | 2,592 | 2.703125 | 3 | [
"MIT"
] | permissive | #![allow(dead_code, unused)]
use std::{
sync::{Arc, Condvar, Mutex},
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
};
use futures::Future;
pub struct InlineWaker {
lock: Mutex<()>,
condvar: Condvar,
}
impl InlineWaker {
pub fn new() -> Arc<Self> {
Arc::new(Self {
lock... | true |
18728e2b5d839031096f2d38969b58d54cf3ccb4 | Rust | Udiknedormin/fuzzy_systems | /src/expr.rs | UTF-8 | 4,916 | 4.03125 | 4 | [
"MIT"
] | permissive | //! Fuzzy expressions that can be evaluated on-demand.
//!
//! Expressions are based on a statically-typed `Expr` trait implementors.
//! No `Box` allocations are used, `Expr` is a truly zero-cost abstraction.
//!
//!
//! ## Operators
//!
//! Each implementor, aside from methods provided by the trait, has handy
//! gen... | true |
2cd43a57e21e97730078530f98de540ae785b2a6 | Rust | last-Battle/do-think | /rust-main/rust-2021-3-5/Advanced/day18_smart_pointer/open_box/src/main.rs | UTF-8 | 871 | 3.46875 | 3 | [] | no_license | // 1| 最简单最直接的智能指针是box,其类型为Box<T>。box允许将值放在堆上而不是栈上,留着栈上的则是指向堆数据的指针。除了数据被存储在堆上外,box没有任何性能损失。
//
// 2| box适合用于如下场景:
// (1) 当有一个在编译时未知大小的类型,而又需要再确切大小的上下文中使用这个类型值的时候;(举例子:在一个list环境下,存放数据,但是每个元素的大小在编译时又不确定)
// (2) 当有大量数据并希望在确保数据不被拷贝的情况下转移所有权的时候;
// (3) 当希望拥有一个值并只关心它的类型是否实现了特定trait而不是其具体类型时。
// 3| use box:
fn main() {
l... | true |
94f0c390ec37a8ed4b217c886040b26ac4c78e12 | Rust | brl/pH | /src/vm/kernel_cmdline.rs | UTF-8 | 1,646 | 2.640625 | 3 | [] | no_license | use std::ffi::OsString;
use std::os::unix::ffi::OsStrExt;
fn add_defaults(cmdline: &mut KernelCmdLine) {
cmdline
.push("noapic")
.push("noacpi")
// keyboard reboot
.push("reboot=k")
.push_set_true("panic")
.push("init_on_alloc=0")
.push("init_on_free=0")
... | true |
6c625fcdae5fd84c19395f8130ace2b32a5ac2b9 | Rust | almedso/conreg | /src/target.rs | UTF-8 | 1,023 | 3.9375 | 4 | [
"MIT",
"ISC"
] | permissive | //! # Target Value Input
//!
//! Iterators that are intended as target input for controllers
//!
//! ## Constant Target Value
//!
//! ```rust
//! use conreg::target::*;
//!
//! let mut target = TargetValue(0_isize);
//! for _v in 0..2 { println!("Value is {:?}", target.next()); }
//! target.set(1);
//! for _v in 0..2 {... | true |
255590d2e54eae48b135caae22802527eef15520 | Rust | zhaostu/learning-rust | /syntax/src/main.rs | UTF-8 | 18,927 | 3.921875 | 4 | [] | no_license | use std::cell::Cell;
fn main() {
variable_bindings();
functions();
primitive_types();
comments();
if_();
loops();
ownership();
reference_and_borrowing();
lifetimes();
mutability();
struct_();
enums();
match_();
patterns();
method_syntax();
vectors();
... | true |
ce259c955bfd2a9180db82f11167b42f269c911e | Rust | crazymerlyn/engine | /src/style.rs | UTF-8 | 1,816 | 3.1875 | 3 | [] | no_license | use std::collections::HashMap;
use css::{Value, Stylesheet, matching_rules};
use node::{Node, NodeType, ElementData};
pub type PropertyMap = HashMap<String, Value>;
pub struct StyledNode<'a> {
pub node: &'a Node,
pub specified_values: PropertyMap,
pub children: Vec<StyledNode<'a>>,
}
pub enum Display {
... | true |
8dfdf4c0f43756e3eb9d8b95ee6e223ff120b08b | Rust | orac/name-maker | /src/main.rs | UTF-8 | 5,102 | 3.09375 | 3 | [] | no_license | extern crate rand;
#[macro_use]
extern crate clap;
use std::io;
use std::io::prelude::*;
use std::fs::File;
use std::hash::Hash;
use std::cmp::Eq;
use std::collections::hash_set::HashSet;
use std::collections::hash_map::HashMap;
use rand::Rng;
use rand::distributions::Sample;
#[derive(Debug)]
struct FrequencyTable<T:... | true |
d6a0f1cf9bc72ece4c59f695f06579ac0b7f5331 | Rust | mmstick/popsicle | /gtk/src/ui/content/devices.rs | UTF-8 | 1,870 | 2.78125 | 3 | [
"MIT"
] | permissive | use gtk::*;
pub struct DevicesView {
pub container: Box,
pub list: ListBox,
pub select_all: CheckButton,
}
impl DevicesView {
pub fn new() -> DevicesView {
let image = Image::new_from_icon_name("drive-removable-media-usb", 6);
image.set_valign(Align::Start);
let topic =... | true |
077d15dfd26942d8814a224ac39c7e9f9aa6e1fc | Rust | kmeisthax/retrogram | /src/memory/cptr.rs | UTF-8 | 19,296 | 3.109375 | 3 | [] | no_license | //! "Contextual" pointers that contain any platform or architectural state
//! necessary to understand them.
use crate::maths::FromStrRadix;
use crate::reg;
use crate::reg::Symbolic;
use num::traits::Bounded;
use serde::de;
use serde::{Deserialize, Deserializer, Serialize};
use std::cmp::{Ord, Ordering, PartialEq, Par... | true |
d5f7c24d824607c8339dab8ff32070d8a2dfd0c4 | Rust | heaths/azure-sdk-for-rust | /sdk/identity/src/token_credentials/environment_credentials.rs | UTF-8 | 4,075 | 2.796875 | 3 | [
"MIT",
"LGPL-2.1-or-later",
"LicenseRef-scancode-generic-cla"
] | permissive | use super::{ClientSecretCredential, TokenCredentialOptions};
use azure_core::auth::{TokenCredential, TokenResponse};
use azure_core::error::{Error, ErrorKind, ResultExt};
use azure_core::HttpClient;
use std::sync::Arc;
const AZURE_TENANT_ID_ENV_KEY: &str = "AZURE_TENANT_ID";
const AZURE_CLIENT_ID_ENV_KEY: &str = "AZUR... | true |
9a21a34d830817da0fc7a1cdc5c0e3a869aa3d6d | Rust | rajcspsg/rust_tensor | /rust_import/burrowing/burrow1.rs | UTF-8 | 532 | 3.265625 | 3 | [] | no_license | //import std::vec::Vec;
fn re(v: Vec<i32>) -> Vec<i32> {
println!("{}", v[120] + v[111]);
v
}
fn burrow1(v: &Vec<i32>) {
println!("{}", (*v)[10] + (*v)[12]);
}
fn burrow2(v: &Vec<i32>) {
println!("{}", &v[10] + &v[12]);
}
fn main() {
let mut v = Vec::new();
for i in 1..1000 {
v.pus... | true |
64d7073cdf7071d1e2a9514c973bf68dd76efc59 | Rust | mitermayer/augmented-audio | /crates/spikes/example-druid-audio-viz/src/buffer_analyser.rs | UTF-8 | 955 | 2.75 | 3 | [
"MIT"
] | permissive | use atomic_queue::Queue;
use audio_processor_traits::{AudioBuffer, AudioProcessor, AudioProcessorSettings};
use basedrop::{Handle, Shared};
pub struct BufferAnalyserProcessor {
buffer: Shared<Queue<f32>>,
}
impl BufferAnalyserProcessor {
pub fn new(handle: &Handle) -> Self {
BufferAnalyserProcessor {
... | true |
7d338895d58592fa5bf3059d7b806957addd4e00 | Rust | Kromey/rustywire | /src/message/record.rs | UTF-8 | 1,332 | 2.828125 | 3 | [] | no_license | mod parameters;
use bytes::Bytes;
pub use parameters::*;
use std::fmt;
#[derive(Clone, Debug)]
pub struct PartialRecord {
pub label: String,
pub rrtype: RRType,
pub class: Class,
}
impl fmt::Display for PartialRecord {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} {:?} ... | true |
5a84d8a563d277aa36da8922d44e63a1a0e45595 | Rust | RNAcentral/rnacentral-import-pipeline | /utils/precompute/src/metadata/orf.rs | UTF-8 | 1,157 | 2.765625 | 3 | [
"GPL-1.0-or-later",
"Apache-2.0",
"Artistic-1.0-Perl",
"LicenseRef-scancode-other-copyleft",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::{
collections::HashSet,
iter::FromIterator,
path::Path,
};
use serde::{
Deserialize,
Serialize,
};
use anyhow::Result;
use rnc_core::grouper;
#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub struct Orf {
pub id: usize,
pub urs_id: usize,
urs_taxid: String,
source:... | true |
9818f5bd001ac3fee07828c3d308850168adff66 | Rust | konradmoesch/rust_asio | /src/ffi/sa/nobsd.rs | UTF-8 | 1,169 | 2.6875 | 3 | [
"MIT"
] | permissive | use ffi::sockaddr;
use std::mem;
#[derive(Clone)]
pub struct SockAddr<T> {
pub sa: T,
pub sa_len: u8,
}
impl<T> SockAddr<T> {
pub fn size(&self) -> u8 {
self.sa_len
}
pub fn resize(&mut self, sa_len: u8) {
self.sa_len = sa_len
}
}
impl<T: super::PodTrait> SockAddr<T> {
p... | true |
f5a03c80ecb9d3b0a0b203566b612cd228a98fb3 | Rust | dylanmckay/compiler | /src/ir/types/array.rs | UTF-8 | 788 | 3.5 | 4 | [
"MIT"
] | permissive | use types::{Type,TypeTrait};
use std::fmt;
/// Represents an array of values of a single `Type`.
#[derive(Clone,Eq,PartialEq,Debug)]
pub struct Array
{
count: u64,
ty: Box<Type>,
}
impl Array
{
pub fn empty(ty: Type) -> Self {
Array::new(0, ty)
}
pub fn new(count: u64, ty: Type) -> Array ... | true |
57a597bd8d6cc7d2c07781fc5eba84436fc11083 | Rust | kairosswag/aoc | /2017/d12/src/main.rs | UTF-8 | 1,965 | 3.15625 | 3 | [] | no_license | extern crate regex;
use regex::*;
use std::collections::HashMap;
use std::collections::HashSet;
fn main() {
let input = include_str!("../input/input");
let re = Regex::new(r"([0-9]*)[^0-9]*").unwrap();
let mut map = HashMap::new();
for line in input.lines() {
let mut numbers: HashSet<u32> = Has... | true |
9aabaca47f2b6aca795ec47c71715f1cafcf527a | Rust | davibusanello/exercism | /rust/armstrong-numbers/src/lib.rs | UTF-8 | 367 | 3.1875 | 3 | [
"MIT"
] | permissive | pub fn is_armstrong_number(num: u32) -> bool {
if num == 0 {
return true;
};
let number_as_string = num.to_string();
let mut sum: u32 = 0;
for digit_char in number_as_string.chars() {
sum += digit_char
.to_digit(10)
.unwrap()
.pow(number_as_string... | true |
13fdbc830c00a5eab797fdb5a3dbb1b4858f7535 | Rust | shirshak55/druid-npm-scripts | /src/main.rs | UTF-8 | 4,864 | 2.5625 | 3 | [] | no_license | #![windows_subsystem = "windows"]
use druid::{text::EditableText, widget::prelude::*};
use druid::text::TextStorage;
use druid::{
widget::{CrossAxisAlignment, Flex, Label, LineBreaking, MainAxisAlignment, Scroll, TextBox},
Color,
};
use druid::{AppLauncher, Data, Lens, TextAlignment, UnitPoint, WidgetExt, Win... | true |
a1bbf1538810e1ba6272621389ff8b8d29060dfc | Rust | Sh3Rm4n/stm32f3xx-hal | /src/adc.rs | UTF-8 | 21,843 | 2.921875 | 3 | [
"BSD-3-Clause",
"0BSD"
] | permissive | //! # Analog to Digital Converter.
//!
//! ## Examples
//!
//! Check out [examles/adc.rs][].
//!
//! It can be built for the STM32F3Discovery running
//! `cargo build --example adc --features=stm32f303xc`
//!
//! [examples/adc.rs]: https://github.com/stm32-rs/stm32f3xx-hal/blob/v0.8.1/examples/adc.rs
use cortex_m::asm... | true |
a93c1c974f19bad51eab597353be7437282eafc9 | Rust | yzimhao/uopen | /src/lib.rs | UTF-8 | 2,860 | 2.78125 | 3 | [] | no_license | #[macro_use]
extern crate log;
extern crate simple_logger;
extern crate config;
use std::path::{Path, PathBuf};
use std::env;
use config::*;
use std::io;
use std::process::{Command, ExitStatus, exit, Stdio};
use std::ffi::OsStr;
pub fn get_config(key: &str) -> String {
info!("read the config file");
let... | true |
593304b863917ff7c91790e7d76ba7b05b9d1fe6 | Rust | yamagata-akita/rust_tutorial | /chapter_7/ownership/src/7_2_copy_semantics.rs | UTF-8 | 1,670 | 3.640625 | 4 | [] | no_license | // 構造体や列挙型にCopyトレイト(std::marker::Copy)を実装すると、値がムーブ!するのではなく、
// コピーされるようになる
// let p2 = p1というシンタックスが、型によってはコピーセマンティクスに変わる
// 構造体や列挙型が以下のすべての条件を満たすとき、Copyトレイトを実装できる
// 1.その型(構造体や列挙型)のすべてのフィールドの型がCopyトレイトを実装している
// 例えばi32型はCopyトレイトを実装している
// 2.その型自身とすべてのフィールドの型がデストラクタ(Dropトレイト)を実装していない
// ヒープ領域を使用するデータ型(Box<T>, Vec<T... | true |
1ccea9fa39ea058ec918b61467c0e3ceba468781 | Rust | Eroc33/AoC2017 | /src/bin/10.rs | UTF-8 | 1,642 | 3.359375 | 3 | [] | no_license | fn flip_slice<T>(slice: &mut[T], start: usize, len: usize){
if len == 0 {
return;
}
let mut first = start % slice.len();
let mut last = (first + (len-1)) % slice.len();
for _ in 0..(len/2){
slice.swap(first,last);
first = (first + 1) % slice.len();
if last == 0 {
... | true |
cee4eaef9617022790131f1db2730d20995b51ed | Rust | gwafotapa/Information-set-decoding | /src/instance/mod.rs | UTF-8 | 2,319 | 2.890625 | 3 | [] | no_license | use std::{
error::Error,
fs::File,
io::{BufRead, BufReader},
rc::Rc,
};
use mceliece::{finite_field::Field, finite_field::F2, matrix::ColVec, matrix::Mat};
pub struct Instance {
n: usize,
w: usize,
h: Mat<F2>,
s: ColVec<F2>,
}
impl Instance {
pub fn new(n: usize, w: usize, h: Mat<... | true |
70e184d480f7a9922f95ee0da9d93f87516d69a0 | Rust | nebocco/MazeGame | /src/resources/mod.rs | UTF-8 | 471 | 3.265625 | 3 | [
"MIT"
] | permissive | #[derive(Clone, Copy, Debug, PartialEq)]
pub enum GameState {
Play,
Win
}
pub struct CurrentStageData {
pub state: GameState,
pub stage: usize
}
impl Default for CurrentStageData {
fn default() -> Self {
Self {
state: GameState::Play,
stage: 0
... | true |
ecf4f17cd61b67207c67ddfec157914dbe7899d8 | Rust | ToxicGLaDOS/text_editor | /src/document.rs | UTF-8 | 244 | 2.59375 | 3 | [] | no_license | pub struct Document {
pub path: String,
pub lines: Vec<String>,
}
impl Document {
pub fn new() -> Document{
Document{
path: String::from("test.txt"),
lines: vec![String::from("")]
}
}
}
| true |
55d25cab09f23eb23ee81c16056fb4cc5a433d06 | Rust | kchmck/static_fir.rs | /src/lib.rs | UTF-8 | 5,485 | 3.25 | 3 | [
"MIT"
] | permissive | //! Finite-impulse response (FIR) convolution with static tap coefficients.
#![feature(conservative_impl_trait)]
extern crate num;
use std::ops::{Add, Mul, Deref, DerefMut};
use num::traits::Zero;
/// Provides a sequence of coefficients and storage for sample history.
pub trait FIRCoefs: Default + Deref<Target = [... | true |
d6de9d4c1c90a29bbdbc12b3e3d5cd426d0de3d2 | Rust | Krout0n/vecmat-rs | /src/complex/quaternion.rs | UTF-8 | 14,291 | 3.34375 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use crate::{
complex::Complex,
matrix::Matrix4x4,
traits::{Conj, Dot, NormL1, NormL2, Normalize},
vector::{Vector3, Vector4},
};
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, Sub, SubAssign};
use num_traits::{Float, Num, One, Zero, Inv};
/// Quaternion.
#[repr(transparent)]
... | true |
f43240e40bc54d4d695a3135429df036f2e0a7a1 | Rust | rmundy/rg3d | /src/scene2d/sprite.rs | UTF-8 | 654 | 2.59375 | 3 | [
"MIT"
] | permissive | use crate::core::color::Color;
use crate::{core::visitor::prelude::*, resource::texture::Texture, scene2d::base::Base};
use std::ops::{Deref, DerefMut};
#[derive(Default, Visit)]
pub struct Sprite {
base: Base,
texture: Option<Texture>,
color: Color,
}
impl Deref for Sprite {
type Target = Base;
... | true |
72d0b416f850b169e908d7730998ef792285a675 | Rust | yoshihitoh/razy-cwlogs | /src/ui/widget/debug.rs | UTF-8 | 3,092 | 2.796875 | 3 | [] | no_license | use std::collections::VecDeque;
use chrono::{DateTime, Local};
use tui::buffer::Buffer;
use tui::layout::{Constraint, Direction, Layout, Rect};
use tui::widgets::{List, ListItem};
use crate::event::Key;
use crate::ui::theme::WidgetStyle;
use crate::ui::widget::helper::{apply_item_style, default_block_with_style};
use... | true |
d44df07297df7f0d39e37f3c9bd904b09bd83fdb | Rust | terakilobyte/rustsweeper | /src/cell.rs | UTF-8 | 566 | 2.71875 | 3 | [] | no_license | use ggez::graphics::Point2;
#[derive(Clone, Debug)]
pub struct Cell {
pub position: Point2,
pub rust_count: u8,
pub is_rust: bool,
pub is_hidden: bool,
pub game_over: bool,
pub is_flagged: bool,
pub scaling: f32,
}
impl Cell {
pub fn new(position: Point2, is_rust: bool) -> Self {
... | true |
8f958fa3cdcb3c48e931dd7605a82f8635fdba59 | Rust | jlgerber/bakbuster | /src/utils.rs | UTF-8 | 1,145 | 3.4375 | 3 | [] | no_license | use errors::BBError;
use std::env;
use std::path::PathBuf;
/// Retrieve the current exe directory as a PathBuf or return a ConversionError
pub fn path_to_executable() -> Result<PathBuf, BBError> {
let this_file = env::current_exe().map_err(|e| BBError::ConversionError(format!("Unable to get current_exe: {}",e)))?;... | true |
f85c30a1505f2550343dfa39ffca7591576d5ebb | Rust | brl/citadel-tools | /libcitadel/src/exec.rs | UTF-8 | 5,697 | 2.640625 | 3 | [] | no_license | use std::env;
use std::fs::File;
use std::io::{self,Seek,Read,BufReader,BufRead,SeekFrom};
use std::path::{Path,PathBuf};
use std::process::{Command,ExitStatus,Stdio};
use crate::Result;
#[macro_export]
macro_rules! cmd {
($cmd:expr, $e:expr) => { $crate::Exec::new($cmd).run(String::from($e)) };
($cmd:expr, $... | true |
f1f2332de97a116818302eb82e79084ab3590d0d | Rust | mr1sunshine/mapbox-maps-rs | /src/geo/mercator_coordinate.rs | UTF-8 | 2,657 | 3.4375 | 3 | [
"BSD-3-Clause"
] | permissive | use super::LngLat;
use num::traits::Float;
const PI: f64 = std::f64::consts::PI;
const EARTH_CIRCUMFRENCE: f64 = 2.0 * PI * super::EARTH_RADIUS; // meters
fn circumfrence_at_latitude<T: Float>(lat: T) -> T {
T::from(EARTH_CIRCUMFRENCE).unwrap()
* (lat * T::from(PI).unwrap() / T::from(180.0).unwrap()).cos(... | true |
6a8dc3611af6c72a5bb590f85ad775e20e7b23ad | Rust | sogapalag/cplib | /src/ds/seg/tree.rs | UTF-8 | 2,056 | 3.109375 | 3 | [] | no_license | use crate::algebra::Monoid;
use std::marker::PhantomData;
use std::ops::Range;
/// Segment tree(iterative implementation).
#[derive(Clone, Debug)]
pub struct SegTree<T, M> {
N: usize,
a: Vec<T>,
_m: PhantomData<M>,
}
impl<T, M> SegTree<T, M>
where
T: Monoid<M> + Copy,
{
pub fn new(n: usize) -> Sel... | true |
cd31da69f50f08439b8b9874b7f4dcf96b6c4fc8 | Rust | ryanjackgit/rustunsafedatastruct | /src/vec.rs | UTF-8 | 7,390 | 3.09375 | 3 | [] | no_license | use std::alloc::{self, dealloc, Layout};
use std::ptr;
use std::mem;
use std::fmt::Debug;
use std::ops::{Index,IndexMut,Range};
use std::marker::PhantomData;
pub struct ManVec<T> {
// in std implemention,ptr is a Unique<T> ,It's own type T,if T is Send/Sync,Vec<T> is Send/Sync.
ptr: *mut T,
cap:usize,
l... | true |
1640ed1d049b3a533771457720e1b6361fdfe887 | Rust | MROS/carbonbond | /src/user/password.rs | UTF-8 | 2,860 | 2.828125 | 3 | [] | no_license | use rand::Rng;
use diesel::prelude::*;
use crate::db::{models as db_models, schema as db_schema};
use crate::custom_error::{Fallible, Error};
use crate::user::{email, find_user_by_id, find_user_by_name};
pub fn change_password(
conn: &PgConnection,
user_id: i64,
old_password: String,
new_password: Stri... | true |
2da293a9642cfe13995713e7789069d1e5c3b20f | Rust | yongkyuns/noon_egui | /src/geom/primitive/grid.rs | UTF-8 | 2,182 | 2.796875 | 3 | [] | no_license | use super::Step;
use crate::appearance::Stroke;
// use crate::geom::path::WithPath;
use crate::{Spatial, Visual, WithSpatial, WithVisual};
pub struct Grid {
visual: Visual,
spatial: Spatial,
pub step: Step,
}
impl Default for Grid {
fn default() -> Self {
Self {
visual: Visual::Str... | true |
e46f4a70a2d211114c5cdc59859037ed90016274 | Rust | scottschroeder/advent_of_code_2019 | /src/challenges/day18/map_reader.rs | UTF-8 | 4,412 | 3.109375 | 3 | [
"MIT"
] | permissive | use super::{Key, Tile};
use anyhow::anyhow as ah;
use std::fmt;
#[derive(Debug, Clone)]
pub(crate) struct Map {
pub(crate) data: Vec<Tile>,
pub(crate) width: usize,
}
pub(crate) struct LRNeighbors {
pub(crate) node: (usize, Tile),
pub(crate) l: Option<(usize, Tile)>,
pub(crate) r: Option<(usize, T... | true |
d352aebcc5ec658ed9f88b5972020dec6923ae22 | Rust | kentfredric/powerctl | /libpowerctl/src/output.rs | UTF-8 | 1,707 | 2.84375 | 3 | [] | no_license | use crate::{outpairs::OutPairs, Maybe};
use std::{
fs,
io::Error,
path::{Path, PathBuf},
};
pub(super) trait Output {
fn heading(&self) -> String;
fn fields(&self) -> Vec<String>;
fn root(&self) -> PathBuf;
fn extras(&self) -> Maybe<Vec<OutPairs>, Error> { Maybe::None }
fn field_value... | true |
0cb7748102c8ec3a65c26a720ed102fa1c00772b | Rust | vab9/pir-project2017 | /src/nn/mod.rs | UTF-8 | 7,203 | 3.171875 | 3 | [
"MIT"
] | permissive | extern crate serde_json;
pub mod learning;
use input::util;
use na::{DMatrix, DVector, IterableMut};
use rand;
use rand::distributions::normal::StandardNormal;
use rand::Rng;
use std::fs::File;
use std::io::{self, BufReader, BufWriter};
use std::str;
use structs::serialnet::SerializableNet;
/// Artificial Neural Ne... | true |
6bd3968176f39b383986e7ca2f9cc58908edccdc | Rust | MirecIT/amethyst | /amethyst_window/src/config.rs | UTF-8 | 6,670 | 2.953125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use std::path::PathBuf;
use image::{self, DynamicImage};
use serde::{Deserialize, Serialize};
#[cfg(target_os = "windows")]
use winit::platform::windows::WindowBuilderExtWindows;
use winit::{
dpi::Size,
window::{Fullscreen, Icon, WindowAttributes, WindowBuilder},
};
use crate::monitor::{MonitorIdent, Monitors... | true |
6b72fcbc5f22832eaa12af575f71f21969ebda25 | Rust | nyarly/d2tools | /src/destiny/headers.rs | UTF-8 | 632 | 2.765625 | 3 | [] | no_license | use std::fmt::{self, Display};
use hyper::header;
use hyper;
#[derive(Clone)]
pub struct XApiKey {
key: String,
}
impl XApiKey {
pub fn key(k: String) -> XApiKey {
XApiKey { key: k }
}
}
impl Display for XApiKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.key)
}
}
... | true |
0c6f1038ced3b78463ea9838f4a9eb26c2164170 | Rust | ry/tokio | /tokio-signal/src/windows.rs | UTF-8 | 10,582 | 2.796875 | 3 | [
"MIT"
] | permissive | //! Windows-specific types for signal handling.
//!
//! This module is only defined on Windows and contains the primary `Event` type
//! for receiving notifications of events. These events are listened for via the
//! `SetConsoleCtrlHandler` function which receives events of the type
//! `CTRL_C_EVENT` and `CTRL_BREAK_... | true |
4991e303636e9f2798f546cf9e0ecc8d977df1e8 | Rust | czyczk/LeetCode | /rust/lc-188/src/solution.rs | UTF-8 | 933 | 2.96875 | 3 | [] | no_license | pub struct SolutionOriginal {}
impl SolutionOriginal {
pub fn max_profit(k: i32, prices: Vec<i32>) -> i32 {
let n = prices.len();
if n == 0 {
return 0;
}
let k = (k as usize).min(n / 2);
let mut buy = vec![vec![0; k + 1]; n];
let mut sell = vec![vec![0;... | true |
eee46be8dab83a180f69a82b25f45a4e4f0d639f | Rust | saethlin/veneer | /src/spinlock.rs | UTF-8 | 1,201 | 3.0625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use core::{
cell::UnsafeCell,
ops::{Deref, DerefMut},
sync::atomic::{
AtomicBool,
Ordering::{Acquire, Release},
},
};
pub struct SpinLock<T> {
locked: AtomicBool,
contents: UnsafeCell<T>,
}
unsafe impl<T> Sync for SpinLock<T> {}
pub struct SpinLockGuard<'a, T> {
lock: &'a ... | true |
b76dd3a8a293bc7219bfc671bd353dbebc5505f1 | Rust | wh75er/compilers | /cfg2proper/src/grammar/transformations.rs | UTF-8 | 15,596 | 2.734375 | 3 | [] | no_license | use crate::grammar::{Grammar, Production, Symbol, SymbolsKind, EPSILON_SYMBOL, U_CODEPOINTS};
use itertools::Itertools;
use std::collections::{HashMap, HashSet};
use std::iter;
const MAP_ELEMENT_NOT_FOUND_MSG: &str = "There must be at least one production for requested grammar non-terminal";
pub fn get_productive(g: ... | true |
e384c78e18520d9504555363e65fac5ff6bbaaac | Rust | skywhale/adventofcode2018 | /day2-part2/src/main.rs | UTF-8 | 1,745 | 3.296875 | 3 | [] | no_license | use std::collections::hash_map::HashMap;
use std::fs;
use std::vec::Vec;
fn get_common_chars(id1: &str, id2: &str) -> String {
id1.chars().zip(id2.chars())
.filter_map(|(c1, c2)| if c1 == c2 { Some(c1) } else { None })
.collect()
}
// A matcher for constant-time operation.
fn match_id<'a>(id: &'a ... | true |
0798017090fb31f48a940bec6b50b0967c627279 | Rust | Hexilee/data-structure-rs | /src/lib.rs | UTF-8 | 496 | 3.15625 | 3 | [] | no_license | use std::cmp::Ord;
mod sort;
pub mod structure;
pub trait Pair {
type Key: Ord;
type Value;
fn key(&self) -> &Self::Key;
fn value(&self) -> &Self::Value;
fn set_value(&mut self, value: Self::Value);
}
impl<K: Ord, V> Pair for (K, V) {
type Key = K;
type Value = V;
fn key(&self) -> &S... | true |
d03b7817e3695d92e729e97177907d4c7f4549fd | Rust | crate-ci/typos | /crates/typos-cli/src/report.rs | UTF-8 | 5,551 | 2.8125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | #![allow(clippy::needless_update)]
use std::borrow::Cow;
pub trait Report: Send + Sync {
fn report(&self, msg: Message) -> Result<(), std::io::Error>;
}
#[derive(Clone, Debug, serde::Serialize, derive_more::From)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "type")]
#[non_exhaustive]
pub enum Message<'m> {... | true |
23703a2dc67b78975a34f16d0720710fa50d47c6 | Rust | jaym/mal-rust | /src/reader.rs | UTF-8 | 11,933 | 3.21875 | 3 | [] | no_license | use crate::types::{MalAtom, MalVal};
use std::iter::Peekable;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum ParseError {
#[error("Unexpected EOF")]
#[allow(clippy::upper_case_acronyms)]
EOF,
#[error("Unexpected token {0}")]
UnxpectedToken(String),
#[error("Unexpected escapse sequence \... | true |
d4f06e899258f890f8827591808b6c90f1dde596 | Rust | Na1w/transmitproxy | /src/main.rs | UTF-8 | 1,455 | 2.78125 | 3 | [] | no_license | use crate::utils::{parse_http_header, read_stream_line};
use std::net::{TcpListener, TcpStream};
use std::sync::{Arc, RwLock};
use std::thread;
use std::time::Duration;
mod utils;
mod arbitrator;
fn main() {
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
let counter: Arc<RwLock<i32>> = Arc::new(R... | true |
ca537990f81ba26308273784314c4f34161fe4df | Rust | nbaksalyar/socket-collection | /src/error.rs | UTF-8 | 2,498 | 2.703125 | 3 | [
"BSD-3-Clause",
"MIT"
] | permissive | use maidsafe_utilities::serialisation::SerialisationError;
use mio::timer::TimerError;
use std::io;
#[cfg(features = "protocol-udt")]
use udt_extern::UdtError;
quick_error! {
/// Common module specific error
#[derive(Debug)]
pub enum SocketError {
/// IO error
Io(e: io::Error) {
... | true |
6da662a2d0c39a5910ff9d6298f7a379f2dd0ad8 | Rust | forgeyao/rust-learning | /RustByExample/3/Structures/main.rs | UTF-8 | 1,651 | 3.625 | 4 | [
"Apache-2.0"
] | permissive | /**
* 3种 struct
* tuple struct
* C 风格 struct
* unit struct
* https://doc.rust-lang.org/rust-by-example/custom_types/structs.html
*/
#[derive(Debug)]
struct Person {
name: String,
age: u8,
}
// unit struct
struct Unit;
// tuple struct
struct Pair(i32, f32);
struct Point {
x: f32,
y: f32,
}
#[a... | true |
7cefbb8e505d57626e1764f19e1be93bc27e4ee7 | Rust | niranjan-nagaraju/Development | /rust/rust_99_problems/src/my_reverse.rs | UTF-8 | 1,603 | 3.921875 | 4 | [] | no_license | /*
Problem 5
(*) Reverse a list.
Example in Haskell:
λ> myReverse "A man, a plan, a canal, panama!"
"!amanap ,lanac a ,nalp a ,nam A"
λ> myReverse [1,2,3,4]
[4,3,2,1]
*/
use itertools::fold;
// Move head of each iteration to the end
// creating a reversed list
pub fn my_reverse<T: Copy>( list: &[T] ) -> Vec<T> {
... | true |
4c229c9e6619847099c959bdb3d84006abe8f1e9 | Rust | sflanaga/clutch | /src/cli.rs | UTF-8 | 2,235 | 2.921875 | 3 | [] | no_license | use anyhow::{anyhow, Context, Result};
use structopt::StructOpt;
pub const TU32: u32 = 1;
pub const TF64: u32 = 2;
#[derive(StructOpt, Debug, Clone)]
#[structopt(
rename_all = "kebab-case",
global_settings(& [
structopt::clap::AppSettings::ColoredHelp,
structopt::clap::AppSettings::UnifiedHelpMessage
]),
)]
pub struc... | true |
d900bf90658a57b5b7eb6ee80bb5fdad9be7a6fb | Rust | frewsxcv/helixhttpclient | /src/lib.rs | UTF-8 | 1,254 | 2.6875 | 3 | [
"LicenseRef-scancode-public-domain",
"CC0-1.0"
] | permissive | #![recursion_limit="1024"]
#[macro_use]
extern crate helix;
extern crate hyper;
use std::io::Read;
ruby! {
class HelixHttpClient {
struct {
url: String,
}
def initialize(helix, url: String) {
HelixHttpClient {
helix,
url,
... | true |
28d20f114511247c55d5cd5cafe1145a16c2e104 | Rust | metrics-rs/quanta | /src/upkeep.rs | UTF-8 | 6,943 | 3.3125 | 3 | [
"MIT"
] | permissive | use crate::{set_recent, Clock};
use std::{
fmt, io,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
thread::{self, JoinHandle},
time::Duration,
};
static GLOBAL_UPKEEP_RUNNING: AtomicBool = AtomicBool::new(false);
/// Ultra-low-overhead access to slightly-delayed time.
///
/// In s... | true |
a23248414d3bfac7c9ffc80ed17ea3334c7aadef | Rust | rust-lang/glacier | /fixed/68393.rs | UTF-8 | 263 | 2.515625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | pub enum EFoo { A }
pub trait Foo {
const X: EFoo;
}
struct Abc;
impl Foo for Abc {
const X: EFoo = EFoo::A;
}
struct Def;
impl Foo for Def {
const X: EFoo = EFoo::A;
}
pub fn test<A: Foo, B: Foo>(arg: EFoo) {
let A::X = arg;
}
fn main() {}
| true |
58dbc72f50e18150b72fa3bcefd6ca5cf7f3d979 | Rust | kdar/ckbackup | /lib/kernel32x/build.rs | UTF-8 | 550 | 2.5625 | 3 | [
"MIT"
] | permissive | // Copyright © 2015, Peter Atashian
// Licensed under the MIT License <LICENSE.md>
pub fn link(name: &str, bundled: bool) {
use std::env::var;
let target = var("TARGET").unwrap();
let target: Vec<_> = target.split('-').collect();
if target.get(2) == Some(&"windows") {
println!("cargo:rustc-link-lib=dylib={}... | true |
d482ca18dfa75ce3c4e1b27a7da2409733bca0f1 | Rust | htrefil/tpattern | /src/main.rs | UTF-8 | 1,365 | 3.15625 | 3 | [] | no_license | #![feature(process_exitcode_placeholder)]
mod model;
mod words;
use model::{Generator, Model};
use rand::rngs::OsRng;
use rand::Rng;
use std::collections::{HashMap, HashSet};
use std::env;
use std::fs;
use std::process::ExitCode;
use words::Words;
fn usage() {
println!("Usage: {} <path> <count>", env!("CARGO_PKG_... | true |
3e309de6bd8a1ea67e62b67c31abcaa6cc2ca9c5 | Rust | sinesc/avec | /src/main.rs | UTF-8 | 244 | 2.84375 | 3 | [] | no_license | extern crate avec;
use avec::AVec;
fn main() {
let x = AVec::<u32>::new(32);
x.push(123);
x.push(345);
x.map(4)
.set(0, 567)
.set(1, 890)
.set(2, 234)
.set(3, 567);
println!("{:?}", x);
}
| true |
da617c390978a9922ace9c3516de414f89985e12 | Rust | standardgalactic/h2o-kubernetes | /deployment/src/client.rs | UTF-8 | 2,062 | 3.140625 | 3 | [
"Apache-2.0"
] | permissive | use std::path::Path;
use kube::{Client, Config};
use kube::config::{Kubeconfig, KubeConfigOptions};
use crate::Error;
/// Constructs a client from a kubeconfig to be found under the specified `kubeconfig` path.
/// Returns default namespace as a second value in the tuple.
/// # Arguments
///
/// `kubeconfig_path` - ... | true |
35a7dfeace40c2163f193e66604e64f58a433d67 | Rust | mrbkap/adventofcode-2016 | /13_cubes/src/main.rs | UTF-8 | 3,244 | 3.1875 | 3 | [] | no_license | use std::collections::{ HashMap, VecDeque };
const FAVORITE_NUM : usize = 1364;
//const TARGET : Point = Point { y: 39, x: 31 };
#[derive(PartialEq, Eq, Hash, Clone)]
struct Point {
x: usize,
y: usize,
}
impl Point {
fn new(x: usize, y: usize) -> Point {
Point { x: x, y: y }
}
fn snew(x: ... | true |
3456177b6c8a11e2483425844374e9db150c7caf | Rust | mocsy/apllib | /src/monadic/arithmetical.rs | UTF-8 | 3,154 | 3.4375 | 3 | [
"Apache-2.0"
] | permissive | use std::ops::Neg;
use rand::{Rng, thread_rng};
use rand::distributions::uniform::SampleUniform;
/// Reciprocal x
/// 1/x
///
/// ```
/// assert_eq!(0.125, apllib::reciprocal(8.0));
/// assert_eq!(0.0078125, apllib::reciprocal(128.0));
/// assert_eq!(0.000000008100000073710001, apllib::reciprocal(123456789.0));
/// ``... | true |
b57e66f4eea6fe7cbb673ed72e257b4d4224524c | Rust | tbremer/adventofcode | /2015/04/src/main.rs | UTF-8 | 1,105 | 3.40625 | 3 | [] | no_license | use md5;
fn main() {
println!("Welcome to day-4 — Running test suite first!");
test_1();
println!("Test suite complete, solving puzzle…");
let input_data = "bgvyzdsv";
println!("Puzzle 1: {:?}", pt_1(&input_data));
println!("Puzzle 2: {:?}", pt_2(&input_data));
}
fn pt_1(base: &str) -> usiz... | true |
a85f322f9b76c22ca8fc40cc0e5540e102404162 | Rust | t-eckert/Wheel-of-Fortune | /src/game/puzzle.rs | UTF-8 | 3,199 | 3.546875 | 4 | [] | no_license | use std::collections::HashMap;
extern crate rand;
use self::rand::Rng;
pub struct Puzzle {
category: String,
solution: String,
current_puzzle_board: String,
pub guesses: Vec<String>,
}
fn get_puzzle() -> (String, String) {
let puzzles: HashMap<&str, Vec<&str>> = [
("Fruit", vec!["APPLE", "... | true |
60a698027fafda7a7e0f93acbc78622aca09e17b | Rust | TobiasFaller/UniFr-Lecture-AlgoDat-Solutions-Rust | /ex14/src/edit_distance.rs | UTF-8 | 2,592 | 3.296875 | 3 | [
"MIT"
] | permissive | use std::cmp::min;
pub fn compute_ed_recursively(x: &str, y: &str) -> usize {
let x = x.chars().collect::<Vec<char>>();
let y = y.chars().collect::<Vec<char>>();
return compute_ed_recursively_int(&x, &y, x.len(), y.len());
}
pub fn compute_ed_via_table(x: &str, y: &str) -> usize {
let x = x.chars().colle... | true |
438f284b1051f5d4414d14eb9ae60d8844d5a862 | Rust | TheIronBorn/ppv | /src/test_utils.rs | UTF-8 | 3,312 | 3.5 | 4 | [] | no_license | //! Test utilities
use crate::{cmp::PartialOrd, fmt::Debug};
/// Tests PartialOrd for `a` and `b` where `a < b` is true.
pub fn test_lt<T: PartialOrd + Debug>(a: T, b: T) {
assert!(a < b, "{:?}, {:?}", a, b);
assert!(b > a, "{:?}, {:?}", a, b);
assert!(!(a == b), "{:?}, {:?}", a, b);
assert!(a != b, ... | true |
f0ad903d5aa65b2d8ea50a50ab1eef32aab217b9 | Rust | deRegent/groks.htm | /exvector/src/main.rs | UTF-8 | 1,132 | 3.3125 | 3 | [] | no_license | const SDR_LENGTH: usize = 21;
const INPUT_LENGTH: usize = 819;
pub struct Column {
sdr: Vec<usize>,
input: Vec<usize>,
result: Vec<usize>
}
fn main() {
let mut columns: Vec<Column> = (0..1024).map(|i| init_column()).collect();
columns.iter_mut().for_each(|c| intersection(c));
columns.iter().fo... | true |
d6104887faa82f42d19b044ed3c2739f499a9cf0 | Rust | MathiasKandelborg/Twitch-Discord-Bot | /src/twitch/chat_bot/msg_parser.rs | UTF-8 | 1,601 | 3.0625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | /* Courtesy of Togglebit, the parser master! */
pub struct TwitchChatMsg {
pub display_name: String,
pub channel_name: String,
pub message: String,
}
// Takes pre-parsed WS Text::Message from twitch chat
pub fn parse_twitch_msg(chat_msg: String) -> Option<TwitchChatMsg> {
if chat_msg.contains("PRIVMSG... | true |
ef5cbb0d43c1d330766f7bff06e56c70fa468464 | Rust | almedso/conreg | /examples/ramp.rs | UTF-8 | 827 | 2.734375 | 3 | [
"MIT",
"ISC"
] | permissive | use conreg::regulation::ramp::{Ramp, RampConstraints};
use core::default::Default;
fn main() {
let rc: RampConstraints = Default::default();
let rc = rc.max_speed(1.0);
println!("{:?}", rc);
let mut rp = Ramp::new(0.1, rc);
rp.set_target_relative_position(10.0);
let rs = rp.clone();
let r... | true |
646ccbf533f2c5d501b0b37f39bd8b492c7b01fb | Rust | Istar-Eldritch/biot | /src/biot/skew.rs | UTF-8 | 1,541 | 3.28125 | 3 | [] | no_license |
pub fn min_skew(genome: &str) -> Vec<i32> {
let mut result: Vec<i32> = vec!();
let skew_result = skew(&genome);
let min = skew_result.iter().min().unwrap();
for i in 0..skew_result.len() {
if &skew_result[i] == min {
result.push(i as i32);
}
}
result
}
pub fn max_skew(genome: &str) -> Vec<i3... | true |
4d5a405ae75145c05f6b521e69e76d5f93393b5d | Rust | Cheshulko/Algorithms | /Leetcode/KRadiusSubarrayAverages.rs | UTF-8 | 727 | 2.71875 | 3 | [] | no_license | // https://leetcode.com/problems/k-radius-subarray-averages
struct Solution {}
impl Solution {
pub fn get_averages(nums: Vec<i32>, k: i32) -> Vec<i32> {
let k = k as usize;
let mut s = nums.iter().take(2 * k).map(|x| *x as i64).sum::<i64>() + nums[0] as i64;
vec![-1; k.min(nums.len())]
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.