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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
ce64665c7c33c2e68f880f2f9572c99805090030 | Rust | ArifSanaullah/rust-all-codes | /defining_method/src/main.rs | UTF-8 | 661 | 4.15625 | 4 | [] | no_license | #[derive(Debug)]
struct Rectangle {
height: u32,
width: u32,
}
impl Rectangle {
// add code here
fn area (&self) -> u32 {
self.width*self.height
}
}
fn main() {
// in function datatype of argument is explicitely defined but in method simply refrence of the argument is passed without data... | true |
0a848245a9f904457e4a2612076d46cef7f6f176 | Rust | FrankvdStam/rustic_light | /src/color.rs | UTF-8 | 1,019 | 3.421875 | 3 | [
"MIT"
] | permissive | use std::fmt::Formatter;
pub trait RgbDevice
{
fn set_color(&mut self, color: Color);
fn set_mode(&mut self, mode: RgbMode);
fn set_speed(&mut self, speed: RgbSpeed);
fn set_brightness(&mut self, brightness: RgbBrightness);
fn get_name(&self) -> &String;
fn display(&mut self);
}
#[allow(dead... | true |
65bb07ecd8bf57dcd89ffb551cfd37298f1999da | Rust | 0xb10ckdev/forest | /src/libp2p/keypair.rs | UTF-8 | 4,287 | 3 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | // Copyright 2019-2023 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT
use tracing::{info, trace};
use crate::{
libp2p::Keypair,
utils::io::{read_file_to_vec, write_to_file},
};
use std::{fs, path::Path};
const KEYPAIR_FILE: &str = "keypair";
/// Returns the libp2p key-pair for the node, gener... | true |
52031cc483f9574293ae30222daeae7c5df0b7bd | Rust | tomasritter/block_encrypt | /tests/lib.rs | UTF-8 | 14,036 | 2.640625 | 3 | [] | no_license | extern crate block_encrypt;
extern crate rand;
extern crate redoxfs;
use block_encrypt::*;
use block_encrypt::header::*;
use block_encrypt::header::EncryptionAlgorithm::*;
use block_encrypt::header::CipherMode::*;
use block_encrypt::header::IVType::*;
use rand::{RngCore, Rng};
use std::fs::File;
use std::io::prelude::... | true |
08bc4d90f9b19566ca118f65c55babc7253284f8 | Rust | stackcats/leetcode | /algorithms/easy/convert_a_number_to_hexadecimal.rs | UTF-8 | 1,385 | 3.296875 | 3 | [
"MIT"
] | permissive | impl Solution {
pub fn to_hex(mut num: i32) -> String {
if num == 0 {
return "0".to_string();
}
let mut bits = vec![0; 32];
let is_negative = num < 0;
num = num.abs();
let mut i = 31;
while num > 0 && i >= 0 {
let r = num % 2;
... | true |
ef310a5af4bcb9988b5026ea6bdad5bdbddf0448 | Rust | danclive/queen-core | /src/packet.rs | UTF-8 | 3,231 | 3.09375 | 3 | [
"MIT"
] | permissive | use std::io::{self, Write};
pub const MTU: u32 = 1400;
#[derive(Debug, Default)]
pub struct Packet {
pub header: Header,
pub chan: String,
pub body: Vec<u8>
}
#[derive(Debug, Default)]
pub struct Header {
bytes: [u8; 8],
}
#[derive(Debug)]
#[repr(u8)]
pub enum Type {
Non,
Con,
Ack,
Rs... | true |
d67a585f16de74a17058f97aece52876b1c1c240 | Rust | svenschmidt75/Rust | /NeuralNetwork/lib/ann/src/ann/layers/input_layer.rs | UTF-8 | 230 | 3 | 3 | [] | no_license | pub struct InputLayer {
nneurons: usize,
}
impl InputLayer {
pub fn new(nneurons: usize) -> InputLayer {
InputLayer { nneurons }
}
pub fn number_of_neurons(&self) -> usize {
self.nneurons
}
}
| true |
8de9ea3c318e6c4d6513b646f601f242094b9209 | Rust | lighter/Leetcode-Rust | /n0241. Different Ways to Add Parentheses/main.rs | UTF-8 | 1,521 | 3.203125 | 3 | [
"MIT"
] | permissive | // Author: Netcan @ https://github.com/netcan/Leetcode-Rust
// Zhihu: https://www.zhihu.com/people/netcan
fn bin_op(a: i32, b: i32, o: char) -> i32 {
match o {
'+' => { a + b },
'-' => { a - b },
'*' => { a * b },
_ => { unreachable!() }
}
}
impl Solution {
pub fn diff_ways... | true |
f1bc4a45b86c32d1d33843e74e3e27a9b89f1c05 | Rust | VirtualRaven/WebGallery | /content-managment/main/src/datamodel/dependency.rs | UTF-8 | 4,539 | 2.65625 | 3 | [
"MIT"
] | permissive | use content_managment_datamodel::datamodel::{Dependencies,Resources,Resource,ResourceProvider,DependencyType,DependencyFuncName};
use std::vec::Vec;
use std::collections::HashMap;
use std::sync::Mutex;
pub type DependencyFunc = Box<dyn Fn(&Resource) -> bool + Send + Sync>;
pub type DependencyData = Mutex<HashMap<Depen... | true |
5b2a9ea538aa098255d9dc74a412142aba80c520 | Rust | daniel-shuy/Mayastor | /mayastor/src/bdev/nexus/nexus_iscsi.rs | UTF-8 | 2,269 | 2.921875 | 3 | [
"Apache-2.0"
] | permissive | //! Utility functions and wrappers for working with iSCSI devices in SPDK.
use std::fmt;
use snafu::Snafu;
use crate::{
core::Bdev,
target::{
iscsi::{create_uri, share, target_name, unshare},
Side,
},
};
#[derive(Debug, Snafu)]
pub enum NexusIscsiError {
#[snafu(display("Bdev not fou... | true |
fdbb9950f560a881e94685176fb008cbb2935c33 | Rust | 3Hren/photon | /src/intersection.rs | UTF-8 | 284 | 2.71875 | 3 | [] | no_license | use crate::vec3::Vec3;
#[derive(Copy, Clone, Debug)]
pub struct Intersection {
pub t: f64,
pub point: Vec3<f64>,
pub normal: Vec3<f64>,
}
impl Intersection {
pub fn new(t: f64, point: Vec3<f64>, normal: Vec3<f64>) -> Self {
Self { t, point, normal }
}
}
| true |
98820a02acd9a41ff9634bd352b20f45879759b2 | Rust | rust-lang/miri | /tests/pass/concurrency/thread_park_isolated.rs | UTF-8 | 437 | 2.953125 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //@ignore-target-apple: park_timeout on macOS uses the system clock
use std::thread;
use std::time::{Duration, Instant};
fn main() {
let start = Instant::now();
thread::park_timeout(Duration::from_millis(200));
// Thanks to deterministic execution, this will wait *exactly* 200ms, plus the time for the su... | true |
59fc10ac0d5d59890e3f0022ab513158f204e18c | Rust | charpercyr/chos | /lib/chos-lib/src/arch/x64/port.rs | UTF-8 | 4,317 | 2.78125 | 3 | [] | no_license | use core::arch::asm;
use core::marker::PhantomData;
use crate::access::*;
pub trait PortData: Copy {
unsafe fn read(port: u16) -> Self;
unsafe fn write(port: u16, value: Self);
}
impl PortData for u8 {
unsafe fn read(port: u16) -> Self {
let value;
asm! {
"inb %dx, %al",
... | true |
1135b57e6c24dcfc6e14c13d2c0f946c285ae2e8 | Rust | IThawk/rust-project | /rust-master/src/test/ui/error-codes/E0229.rs | UTF-8 | 280 | 2.515625 | 3 | [
"MIT",
"LicenseRef-scancode-other-permissive",
"Apache-2.0",
"BSD-3-Clause",
"BSD-2-Clause",
"NCSA"
] | permissive | pub trait Foo {
type A;
fn boo(&self) -> <Self as Foo>::A;
}
struct Bar;
impl Foo for isize {
type A = usize;
fn boo(&self) -> usize { 42 }
}
fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
//~^ ERROR associated type bindings are not allowed here [E0229]
fn main() {
}
| true |
9fc87918c52bb0758c423d368107e004a8b9f613 | Rust | chris-morgan/hyphenation | /tests/lib.rs | UTF-8 | 2,826 | 3.078125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | #[macro_use]
extern crate lazy_static;
extern crate quickcheck;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::{Path};
use quickcheck::{quickcheck, TestResult};
extern crate hyphenation;
use hyphenation::{load, Language, Corpus, Hyphenation, FullTextHyphenation, Standard};
fn fiat_io(lang: Lan... | true |
fa3b7fea71b7d52eb1dcc0af00c4b01be675a756 | Rust | Altair-Bueno/fuzzy-disco | /disco-core/src/mongo/user/alias.rs | UTF-8 | 1,845 | 2.921875 | 3 | [] | no_license | use std::str::FromStr;
use lazy_static::lazy_static;
use regex::Regex;
use rocket::request::FromParam;
use serde::{Deserialize, Serialize};
use crate::mongo::user::result;
use crate::mongo::user::result::UserError;
lazy_static! {
static ref RE: Regex = Regex::new(r"^[a-zA-Z_\-0-9]{4,30}$").unwrap();
}
/// An al... | true |
b392fe01a668759cdc4dee6cfb71c9570ab2f813 | Rust | sensorfu/luomu-libpcap | /luomu-tpacketv3/examples/demo.rs | UTF-8 | 6,804 | 2.90625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #[cfg(target_os = "linux")]
mod linux {
use clap::Parser;
use luomu_tpacketv3 as tpacketv3;
use std::sync::atomic::AtomicBool;
use std::sync::mpsc;
use std::sync::Arc;
use std::thread;
use std::time::Duration;
fn packet_consumer(ch: mpsc::Receiver<Vec<u8>>, stop: Arc<AtomicBool>) {
... | true |
ddca9135adf18f51faf167cbdcf80259339b9ee4 | Rust | Kowalevskaja/nalgebra | /src/geometry/rotation_construction.rs | UTF-8 | 879 | 2.53125 | 3 | [
"BSD-3-Clause",
"BSD-2-Clause"
] | permissive | use num::{Zero, One};
use alga::general::{ClosedAdd, ClosedMul};
use core::{SquareMatrix, Scalar};
use core::dimension::DimName;
use core::storage::OwnedStorage;
use core::allocator::OwnedAllocator;
use geometry::RotationBase;
impl<N, D: DimName, S> RotationBase<N, D, S>
where N: Scalar + Zero + One,
... | true |
90162cd087d431ab18ce7a6d6b366bf53dcc3232 | Rust | mendelt/cmdr | /cmdr/src/runner.rs | UTF-8 | 2,811 | 3.109375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] | permissive | use crate::line_reader::LineReader;
use crate::scope::Scope;
use crate::Line;
use crate::{line_writer::LineWriter, result::Action, CommandResult};
use std::fmt::Debug;
/// Wraps a LineReader and a Scope and allows using the scope to interpret commands from the
/// LineReader
#[derive(Debug)]
pub struct Runner<R: LineR... | true |
537c8aaea1e2722a108e1e71f062b69e12c8d677 | Rust | AIT-S/solidity-rs | /yul/src/lib.rs | UTF-8 | 3,516 | 2.609375 | 3 | [
"MIT"
] | permissive | use serde::{Deserialize, Serialize};
use std::collections::HashMap;
pub type NodeID = i64;
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
#[serde(untagged)]
pub enum ExternalReference {
Untagged(ExternalReferenceData),
Tagged(HashMap<String, ExternalReferenceData>),
}
#[derive(Clone, Debug, Deser... | true |
a56b3eda8aec158377a5ae8df703622c7da878c7 | Rust | chrisrhayden/skel | /src/parse_args.rs | UTF-8 | 2,163 | 3.265625 | 3 | [] | no_license | use std::error::Error;
use clap::Parser;
/// make a project from a skeleton defined in a toml file
#[derive(Parser, Default, Debug)]
pub struct SkelArgs {
/// the skeleton to make, can be the skeleton name or alias
pub skeleton: Option<String>,
/// the name of the new project to make
pub name: Option<... | true |
10ee9d7f6a539458f344f54498e2d56559bcd888 | Rust | U007D/gilded_rose | /rust/src/gilded_rose.rs | UTF-8 | 2,087 | 3.046875 | 3 | [
"MIT"
] | permissive | #[cfg(test)]
mod unit_tests;
use std::string;
use std::vec;
pub struct Item {
pub name: string::String,
pub sell_in: i32,
pub quality: i32,
}
impl Item {
pub const fn new(name: String, sell_in: i32, quality: i32) -> Self {
Self { name, sell_in, quality }
}
}
pub struct GildedRose {
p... | true |
860c653bd3114f06bf1f872f0a2bc0dfe680dc53 | Rust | alicika/redis_mock | /src/bin/frame-with-vec.rs | UTF-8 | 1,025 | 2.609375 | 3 | [] | no_license | use mini_redis::{Frame, Result};
use tokio::net::TcpStream;
pub struct ConnectionVec {
stream: TcpStream,
buffer: Vec<u8>,
cursor: usize,
}
impl ConnectionVec {
pub fn new(stream: TcpStream) -> Self {
ConnectionVec {
stream,
buffer: vec![0; 4096],
cursor: 0,... | true |
d3ac845b271235ddc4ab1fc758ae896bf355c5a0 | Rust | JonShort/rust-book-notes | /variables/src/main.rs | UTF-8 | 284 | 3.171875 | 3 | [
"MIT"
] | permissive | use std::vec;
fn main() {
let sum = 5 + 10;
let difference = 95.5 - 4.3;
let product = 4 * 30;
let quotient = 56.7 / 32.2;
let remainder = 43 % 5;
let tup = (500, 6.4, 1);
let (x, y, z) = tup;
let array = [3; 5];
let vector = vec![1, 2, 3, 4];
}
| true |
9d80afbadda10686c82cd5b06ed44d5a982793d3 | Rust | nahiyan/darwin | /modules/persistent-models/src/lib.rs | UTF-8 | 2,492 | 2.609375 | 3 | [] | no_license | mod helpers;
mod persistent_models;
use helpers::c_string_to_str;
use persistent_models::PersistentModels;
use std::ffi::CString;
use std::os::raw::c_char;
#[repr(C)]
pub struct PMModel {
definition: *const c_char,
fitness: f32,
}
#[no_mangle]
pub extern "C" fn pm_load_definition(definition: *const c_char) -... | true |
63cb246b33043ab85c76b527b83206d5c49c060b | Rust | ndob/kbchatbox | /src/textbuffer.rs | UTF-8 | 5,907 | 3.1875 | 3 | [
"MIT"
] | permissive | extern crate linkify;
use linkify::LinkFinder;
use std::cmp;
use std::collections::vec_deque::VecDeque;
use std::collections::HashSet;
pub struct TextBuffer {
xsize: usize,
ysize: usize,
raw_lines: VecDeque<String>,
}
impl TextBuffer {
pub fn new(max_x_chars: usize, max_y_chars: usize) -> Self {
... | true |
c66ea35e719c5f5f330aecdcca444b9f179a9488 | Rust | mesalock-linux/crates-io | /vendor/time/src/format/mod.rs | UTF-8 | 6,550 | 3.09375 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"Unlicense",
"BSD-3-Clause",
"0BSD"
] | permissive | //! Parsing and formatting various types.
/// Pad a given value if requested.
macro_rules! pad {
($f:ident, $padding:ident, $width:literal, $value:expr) => {
match $padding {
Padding::None => write!($f, "{}", $value),
Padding::Space => write!($f, concat!("{:", stringify!($width), "}... | true |
922eca279d947ded621e5a24f8474051847d4498 | Rust | diesel-rs/diesel | /diesel/src/query_builder/combination_clause.rs | UTF-8 | 9,528 | 2.90625 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Combine queries using a combinator like `UNION`, `INTERSECT` or `EXPECT`
//! with or without `ALL` rule for duplicates
use crate::backend::{Backend, DieselReserveSpecialization};
use crate::expression::subselect::ValidSubselect;
use crate::expression::NonAggregate;
use crate::query_builder::insert_statement::Inser... | true |
afd7087b48b44d6e6e70ecd4e1d0a2621e1f0391 | Rust | nathanesau/data_structures_and_algorithms | /_courses/cmpt225/lecture02/personstudents_rust/src/student.rs | UTF-8 | 475 | 3.65625 | 4 | [] | no_license | use crate::gender::Gender;
use crate::person::Person;
pub struct Student {
pub first_name: String,
pub last_name: String,
pub gender: Gender,
}
impl Person for Student {
fn get_full_name(&self) -> String {
format!("{} {}", self.first_name, self.last_name)
}
fn get_gender(&self) -> Str... | true |
6ca7a11e864c9555c6b947b9000042cb205608d3 | Rust | lpil/arrlang | /src/expr/number.rs | UTF-8 | 713 | 3.53125 | 4 | [] | no_license | use super::Expr;
use std::fmt;
#[derive(Debug, PartialEq)]
pub struct Number(f64);
impl super::Expr for Number {
fn reduce(&self) -> Option<Box<Expr>> {
None
}
}
impl fmt::Display for Number {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let &Number(n) = self;
write!(f, ... | true |
834d15aba533f3434984898b276b1c8f3a3deb08 | Rust | vext01/ykrustc_pv | /src/librustc_yk_link/lib.rs | UTF-8 | 2,037 | 2.546875 | 3 | [
"BSD-3-Clause",
"Apache-2.0",
"BSD-2-Clause",
"MIT",
"LicenseRef-scancode-other-permissive",
"NCSA"
] | permissive | // Copyright 2018 King's College London.
// Created by the Software Development Team <http://soft-dev.org/>.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option... | true |
511c0479d7718c0792b89a06900c3cc831c6adfe | Rust | unnsa/rust | /src/test/ui/issues/issue-48803.rs | UTF-8 | 770 | 2.796875 | 3 | [
"Apache-2.0",
"MIT",
"BSD-3-Clause",
"NCSA",
"LicenseRef-scancode-other-permissive",
"BSD-2-Clause"
] | permissive | // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | true |
08ccd4ccce6c9d78b4ce4d7329362372ccae575b | Rust | Hermitter/roku-ecp-rs | /src/lib.rs | UTF-8 | 3,445 | 3.3125 | 3 | [
"MIT"
] | permissive | //! # Roku ECP
//!
//! This crate provides a wrapper over the [Roku External Control
//! Protocol](https://developer.roku.com/docs/developer-program/debugging/external-control-api.md)
//! which enables a Roku device to be controlled over a local area network
//! through a RESTful API.
//!
//! # Example Usage
//! The cr... | true |
8dfbe8b2f3865defed7872a3d22bd0e48429acaa | Rust | pierreyoda/rustboycolor | /src/cpu/test.rs | UTF-8 | 2,057 | 2.96875 | 3 | [
"MIT"
] | permissive | mod alu8; // 8 bits ALU instructions
mod cb; // CB-prefixed instructions
mod control; // control flow instructions
mod load; // load/store/move instructions
use super::{Cpu, CycleType};
use crate::memory::Memory;
use crate::mmu::MemoryManagementUnit;
const OPCODE_END: u8 = 0xD3;
const OPCODES_LIMIT: u32 = 100;
pub s... | true |
7161593993a277888583aea379718fce19d36fdf | Rust | nullr0ute/rust-psa-crypto | /psa-crypto-sys/src/extras.rs | UTF-8 | 2,581 | 2.734375 | 3 | [
"Apache-2.0"
] | permissive | // Copyright 2020 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
#![allow(non_snake_case)]
//! Additional functionality required that PSA Crypto does not provide
use crate::types::{psa_algorithm_t, psa_key_type_t};
/// Retrieves the tag length from an aead_alg.
/// Note: `aead_alg` is an AE... | true |
392b8408dc9d6a1c57c9abdd5b80bda9ebc86a6c | Rust | Dreae/apollo-ecs | /src/systems.rs | UTF-8 | 627 | 3.03125 | 3 | [] | no_license | use super::{Entity, EntityQuery, World};
/// An `IterativeSystem` iterates over all entities matching its
/// provided `EntityQuery` on every world tick.
pub trait IterativeSystem {
/// Static method to return the query that will be used
/// to filter the world's entities before they are passed
/// to this... | true |
14563a8e4631a74ad61958cbedd80a146c1d2bea | Rust | RustWorks/rust_design_pattern | /abstract_factory/src/main.rs | UTF-8 | 9,812 | 3.359375 | 3 | [
"MIT"
] | permissive | use std::io::prelude::*;
use std::fs::File;
use std::env;
use std::process;
// # Traits
trait Item {
fn make_html(&self) -> String;
}
trait Link : Item {}
trait Tray : Item {
fn add(&mut self, item: Box<Item>);
}
trait Page {
fn make_html(&self) -> String;
}
trait Factory {
type LinkObject;
typ... | true |
9951c4821b5db0c259471b9fe76b089cee69ac92 | Rust | zer0problem/2dRustOpenGLTest | /src/tpixel/vector2.rs | UTF-8 | 174 | 2.96875 | 3 | [] | no_license |
#[derive(Copy, Clone)]
pub struct Vector2 {
pub x : f32,
pub y : f32,
}
impl Vector2 {
pub fn new() -> Vector2 {
Vector2 { x : 0f32, y : 0f32 }
}
}
| true |
ea74815e41ec918905fe7bb5f93ad045ff9e277f | Rust | chubin/oxidoc | /src/conversion/doc_containers.rs | UTF-8 | 7,331 | 2.65625 | 3 | [] | no_license | use store::StoreLocation;
use std::collections::HashMap;
use std::fs;
use std::fmt::{self, Display};
use document::{CrateInfo, ModPath};
use generation::ast_ty_wrappers::Attributes;
use store;
use conversion::wrappers::*;
use conversion::wrappers::TraitItemKind;
use ::errors::*;
pub use self::DocInnerData::*;
/// A... | true |
3e80afbeef75be9572209ebadcc0ed300bd95f4c | Rust | faern/triggered | /tests/sync-wait.rs | UTF-8 | 3,880 | 3.203125 | 3 | [] | no_license | use std::thread;
use std::time::{Duration, Instant};
#[test]
fn single_trigger_first() {
let (trigger, listener) = triggered::trigger();
trigger.trigger();
listener.wait();
}
#[test]
fn single_listen_first() {
let (trigger, listener) = triggered::trigger();
let thread_handle = thread::spawn(move |... | true |
aaf02a208e428f91c4117c3fec649ba36314ccbf | Rust | LemonHX/acidjs-rs | /src/main.rs | UTF-8 | 448 | 2.578125 | 3 | [] | no_license | #![feature(vec_into_raw_parts)]
mod data_structure;
mod opcode;
mod parser_atom;
fn tryvec(vec:*mut u8,a1:usize,a2:usize) -> Vec<u32> {
unsafe {
let mut vec:Vec<u32> = Vec::from_raw_parts(vec as *mut u32,a1,a2);
vec.push(3);
vec
}
}
fn main() {
let mut vec:Vec<u32> = vec![1,2];
l... | true |
4d574fa6afbf7cbae4f0ae2e66273bba0c22c393 | Rust | Emurgo/rust-cardano | /protocol/src/ntt/protocol.rs | UTF-8 | 5,785 | 2.8125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //! Constant and network/IO independent part of network-transport-tcp
use cardano::util::hex;
use std::fmt;
const PROTOCOL_VERSION: u32 = 0x00000000;
/// Light weight connection ID contains a valid NTT light weight connection
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct LightweightConnect... | true |
956aaa5f2e09f4dd636a278675f9a2cdee309403 | Rust | heil-hydra/hydramq-rs | /src/pipeline/mod.rs | UTF-8 | 5,498 | 3 | 3 | [
"MIT"
] | permissive | use linked_hash_map::LinkedHashMap;
use message::message::{Message, Key, Value};
pub struct Pipeline {
handlers: LinkedHashMap<String, Box<Handler>>,
}
#[derive(Debug)]
pub enum PipelineDirection {
Downstream,
Upstream,
}
impl Default for PipelineDirection {
fn default() -> Self {
PipelineDir... | true |
93375fa105d73dff42d8b117a03937f2df682d0f | Rust | cronokirby/mage | /src/image.rs | UTF-8 | 4,208 | 3.5625 | 4 | [
"MIT"
] | permissive | use crate::sdl2::render::{Texture, UpdateTextureError};
/// Represents a Color in RGBA format
///
/// Each component ranges from 0 to 255, with 0 representing no color
/// at all in that component, and 255 representing the most color possible.
/// With the alpha component, however, 0 represents complete transparency,
... | true |
7789e65eb931315fdd1107bb5be85e707ab9472b | Rust | buckle2000/turtle-playback | /src/game.rs | UTF-8 | 3,922 | 2.921875 | 3 | [] | no_license | use rl::Vector2;
use rl::Color;
const FPS: i32 = 120;
const TRANSPARENT_WHITE: Color = Color {
a: 10,
..rl::WHITE
};
#[derive(Clone, Debug)]
pub struct TurtleState {
pub time: f32,
/// in pixels
pub pos: Vector2,
/// in radians
pub rot: f32,
pub is_drawing: bool,
}
pub struct GameSta... | true |
3d0d74e68805de93ab421ae37d5b8fdb9e7f95d3 | Rust | Ainevsia/Leetcode-Rust | /cn/396. 旋转函数/src/main.rs | UTF-8 | 816 | 3.640625 | 4 | [
"BSD-2-Clause"
] | permissive | fn main() {
Solution::max_rotate_function(vec![100]);
}
struct Solution {}
impl Solution {
pub fn max_rotate_function(nums: Vec<i32>) -> i32 {
let n = nums.len() as i32;
let s = nums.iter().sum::<i32>();
let mut f = nums.iter().enumerate()
.map(|(x, y)| { x as i32 * y })
... | true |
7da69fb4aaa0218578260f92eeb5e2ea9ab62594 | Rust | khwilson/advent2018 | /dec09/src/main.rs | UTF-8 | 1,780 | 3.140625 | 3 | [] | no_license | use std::collections::HashMap;
fn main() {
let num_players: i64 = 410;
let max_marble: i64 = 7205900;
let mut circle: HashMap<i64, Link> = HashMap::new();
circle.insert(0, Link {before: 0, after: 0});
let mut player_scores: Vec<i64> = vec![0; num_players as usize];
let mut current_marble = 0... | true |
eee758c6e03d9c2ad4a1eb4ef4d7a365db0f8d07 | Rust | safrannn/leetcode_rust | /src/_0167_two_sum_ii.rs | UTF-8 | 686 | 3.8125 | 4 | [] | no_license | struct Solution;
use std::cmp::Ordering::*;
impl Solution {
pub fn two_sum(numbers: Vec<i32>, target: i32) -> Vec<i32> {
let mut left: usize = 0;
let mut right: usize = numbers.len() - 1;
while left < right {
match (numbers[left] + numbers[right]).cmp(&target) {
... | true |
6c730a7027b692d6e37cd5833fce0a59ff200ffc | Rust | Patrik-Stas/play_with_rust | /old_futures/src/iterator_wrapper_simple.rs | UTF-8 | 1,001 | 3 | 3 | [] | no_license | use std::collections::HashMap;
use failure::_core::iter::{Filter, Map};
pub fn example_iterator_wrapper() {
struct IteratorWrapper<I> {
iter: I
}
impl<I> Iterator for IteratorWrapper<I> where I: Iterator {
type Item = I::Item;
fn next(&mut self) -> Option<Self::Item> {
... | true |
a8acd795a34168c32d283860c44a3c41c2ee5b2b | Rust | zacck-zz/oapth | /oapth/src/utils.rs | UTF-8 | 3,680 | 2.5625 | 3 | [
"Apache-2.0"
] | permissive | use crate::DbMigration;
#[oapth_macros::std_]
macro_rules! loop_files {
($buffer:expr, $iter:expr, $n:expr, $cb:expr) => {{
loop {
for el in crate::iter_n_times($n, &mut $iter) {
$buffer.push(el?);
}
if $buffer.is_empty() {
break;
}
$cb;
$buffer.clear();
}
... | true |
fac4dff160372faf1e461c7cc1e9ec22fcd89f6d | Rust | qingzhu521/paradfs | /src/structure/graph.rs | UTF-8 | 2,931 | 3.28125 | 3 | [] | no_license | use std::collections::HashMap;
use crate::structure::AdjacentList;
#[derive(PartialEq, Debug)]
pub struct Graph {
pub adj: AdjacentList,
pub rev_adj: AdjacentList,
}
unsafe impl Send for Graph {}
unsafe impl Sync for Graph {}
impl Graph {
pub fn new(adj: AdjacentList, rev_adj: AdjacentList) -> Self {
... | true |
ef68414ee180e72be1db9342708b6831990faaa0 | Rust | sancta-simplicitas/MasterPiece | /Rust/sumCalc.rs | UTF-8 | 516 | 3.0625 | 3 | [
"MIT"
] | permissive | use std::io::stdin;
trait KtStd {
fn let_ref<R>(&self, block: fn(&Self) -> R) -> R {
block(self)
}
fn also_mut(&mut self, block: fn(&mut Self)) -> &mut Self {
block(self);
self
}
}
impl<T> KtStd for T {}
fn main() {
loop {
String::new()
.also_mut(|s| {... | true |
bebfec0bf5457a9ca659ac90797a0bd649e7f1aa | Rust | arizuk/programming-contest-solutions | /atcoder/ARC078/D/main2.rs | UTF-8 | 3,407 | 2.796875 | 3 | [] | no_license | #[allow(unused_macros)]
macro_rules! input {
(source = $s:expr, $($r:tt)*) => {
let mut iter = $s.split_whitespace();
let mut next = || { iter.next().unwrap() };
input_inner!{next, $($r)*}
};
($($r:tt)*) => {
let stdin = std::io::stdin();
let mut bytes = std::io::Read... | true |
0e5c06bb1e76bbdec05e1e13e9bab7cbc416b0ec | Rust | cvetaevvitaliy/nrf52840-pac | /src/qspi/cinstrconf.rs | UTF-8 | 24,392 | 2.59375 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #[doc = r" Value read from the register"]
pub struct R {
bits: u32,
}
#[doc = r" Value to write to the register"]
pub struct W {
bits: u32,
}
impl super::CINSTRCONF {
#[doc = r" Modifies the contents of the register"]
#[inline]
pub fn modify<F>(&self, f: F)
where
for<'w> F: FnOnce(&R, &'... | true |
afc99a12b51804f00c66db317a4094017e479277 | Rust | shyela/GildedRose-Refactoring-Kata | /rust/src/main.rs | UTF-8 | 1,154 | 2.890625 | 3 | [
"MIT"
] | permissive |
mod gildedrose;
use gildedrose::{Item, GildedRose};
fn main() {
let items = vec![
Item::new(String::from("+5 Dexterity Vest"), 10, 20),
Item::new(String::from("Aged Brie"), 2, 0),
Item::new(String::from("Elixir of the Mongoose"), 5, 7),
Item::new(String::from("Sulfuras, Hand of Ra... | true |
51a186d10dbbf7c5987f95c9c912ce6be406bb38 | Rust | althea-net/num256_rs | /src/uint256.rs | UTF-8 | 15,323 | 3.125 | 3 | [
"Apache-2.0"
] | permissive | pub use super::Int256;
use bnum::types::U256;
use bnum::BUint;
use num_traits::{
Bounded, CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, FromPrimitive, Num, One, ToPrimitive,
Zero,
};
use serde::ser::Serialize;
use serde::{Deserialize, Deserializer, Serializer};
use std::default::Default;
use std::fmt;
use std... | true |
2dee107f4abe566af583fa7cd7a1b05e27b6b671 | Rust | Djuffin/rusty-chess | /src/search_test.rs | UTF-8 | 1,891 | 3.03125 | 3 | [] | no_license | use fen::parse_fen;
use types::*;
fn pick_best_move(fen:&str, best_move_hint:&str) -> Option<String> {
let pos = parse_fen(fen).unwrap();
let moves = ::move_gen::MovesIterator::new(&pos);
for mv in moves {
let (piece, from_sq, to_sq) = match mv {
OrdinaryMove (ref of) => {
... | true |
df403d19644b813280de12cbe3a4b100afcdf730 | Rust | scoville/tailwind-generator | /pyaco-core/src/lang/elm.rs | UTF-8 | 887 | 2.625 | 3 | [] | no_license | use anyhow::Result;
use askama::Template;
use std::{borrow::Cow, collections::HashSet};
use super::{generate_module_name, LangTemplate};
#[derive(Template)]
#[template(path = "elm.txt")]
pub struct ElmTemplate<'a> {
classes: &'a HashSet<String>,
module_name: Cow<'a, str>,
}
impl<'a> LangTemplate<'a> for ElmT... | true |
744a50a6e7cc80609f1b285acf74aa019d18835b | Rust | Kolsky/syn_derive_layers | /trait_layers/src/lib.rs | UTF-8 | 489 | 2.71875 | 3 | [] | no_license | #![no_std]
pub unsafe trait Layers: Sized {
const COUNT: usize;
fn as_num(&self) -> usize;
fn try_from_num(num: usize) -> Option<Self>;
}
pub trait Root: Layers {}
pub struct LayersIter<L: Layers> {
layer: Option<L>,
}
impl<L: Layers> Iterator for LayersIter<L> {
type Item = L;
fn next(&mut... | true |
660fe6981e0c24fcbfe4a585e506295604befb6b | Rust | PeterUlb/rust-user-service | /src/configuration.rs | UTF-8 | 2,329 | 3.171875 | 3 | [] | no_license | use config::{Config, ConfigError, Environment, File};
use serde::{Deserialize, Serialize};
use std::env;
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Database {
pub url: String,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct App {
pub port: i32,
}
#[derive(Debug, Deserialize, Seri... | true |
3493379883a4f551a338e1ca57b2868bcbb686b2 | Rust | shalzz/cloudflare-rs | /cloudflare/src/endpoints/argo_tunnel/delete_tunnel.rs | UTF-8 | 553 | 2.984375 | 3 | [] | no_license | use surf::http::Method;
use crate::framework::endpoint::Endpoint;
use super::Tunnel;
/// Delete a tunnel
/// https://api.cloudflare.com/#argo-tunnel-delete-argo-tunnel
#[derive(Debug)]
pub struct DeleteTunnel<'a> {
pub account_identifier: &'a str,
pub tunnel_id: &'a str,
}
impl<'a> Endpoint<Tunnel> for Dele... | true |
bd5b0d78a4a3a7d6916e37350192abaa758857ed | Rust | i80and/marian-rs | /src/queryst.rs | UTF-8 | 784 | 3.1875 | 3 | [] | no_license | use regex::Regex;
use std::collections::HashMap;
lazy_static! {
static ref PAT_QUERY_STRING: Regex =
Regex::new(r#"([a-zA-Z]+)=([^&]*)"#).expect("Failed to compile query string regex");
}
pub fn parse_query(queryst: &str) -> HashMap<&str, &str> {
let mut result = HashMap::new();
for group in PAT_Q... | true |
ce5a10aba76feaca83ce4ce27026a5e68f70cd7e | Rust | jvff/netlink | /rtnetlink/src/packets/rtnl/message.rs | UTF-8 | 2,180 | 2.65625 | 3 | [
"MITNFA"
] | permissive | use super::*;
use {AckMessage, ErrorMessage};
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum RtnlMessage {
Done,
Error(ErrorMessage),
Ack(AckMessage),
Noop,
Overrun(Vec<u8>),
NewLink(LinkMessage),
DelLink(LinkMessage),
GetLink(LinkMessage),
SetLink(LinkMessage),
NewAddress(Add... | true |
a623b18b8400818e60c6b903b402d46a036f71fe | Rust | codelusion/concur_sample | /src/main.rs | UTF-8 | 944 | 3.65625 | 4 | [] | no_license | use std::thread;
use std::sync::Arc;
use std::sync::Mutex;
fn main() {
// initial value to share and mutate
// in spawed threads
let shared = 1;
// use Arc to share data with thread
// mutex to allow safe mutation
let s = Arc::new(Mutex::new(shared));
// thread handles
let mut handles ... | true |
26ee1f6b5ba551667ca6b7494993e4ab94b5d66b | Rust | cjpearce/birb | /src/sphere.rs | UTF-8 | 1,053 | 3.203125 | 3 | [] | no_license | use crate::material::Material;
use crate::ray::Ray;
use nalgebra::Point3;
use std::f64;
pub struct Sphere {
center: Point3<f64>,
radius: f64,
material: Material,
}
impl Sphere {
pub fn new(center: Point3<f64>, radius: f64, material: Material) -> Self {
Sphere {
center,
... | true |
b6abb2abb3d051fcc2675b2a9821690872990a4c | Rust | MegatonHammer/linkle | /src/format/nacp.rs | UTF-8 | 9,751 | 2.78125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use crate::format::utils;
use byteorder::{LittleEndian, WriteBytesExt};
use serde_derive::{Deserialize, Serialize};
use std::fs::File;
use std::io::Write;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NacpLangEntry {
pub name: String,
pub author: String,
}
#[derive(Serialize, Deserialize, Debug)]... | true |
03695c1ff2dcede05adbd9ed1c74668250bbad18 | Rust | jfourkiotis/albert | /parser/src/lib.rs | UTF-8 | 38,583 | 3.03125 | 3 | [
"MIT"
] | permissive | use ast::*;
use lexer::Lexer;
use std::collections::HashMap;
use token::*;
use utils::FrontendError;
#[repr(i32)]
#[derive(Debug, Copy, Clone)]
enum Precedence {
Lowest = 10,
Equals = 20, // ==
LessGreater = 30, // > or <
Sum = 40, // +
Product = 50, // *
Power = 60, // ^... | true |
500a7cc963855bdc4b19213195afc249628ea5c0 | Rust | roberto3003/rust-learning-path | /functions/src/main.rs | UTF-8 | 167 | 2.65625 | 3 | [] | no_license | fn display_first_name() {
println!("Bobby");
}
fn display_last_name() {
println!("3003");
}
fn main() {
display_first_name();
display_last_name();
}
| true |
64616b21bb4e2ecf2447c6a5732c659967575231 | Rust | nvzqz/asygnal | /src/unix/pipe.rs | UTF-8 | 4,590 | 2.71875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use mio::{unix::EventedFd, Evented};
use std::{io, mem::MaybeUninit, os::unix::io::RawFd};
/// A pipe suitable for signal handling.
///
/// Note: because this pipe is expected to live throughout the duration of the
/// program, neither end implements `Drop` to close its file descriptors.
pub(crate) fn pipe() -> io::Re... | true |
a90225313dcfdb3706df07f2c79e3d8ca59034b3 | Rust | tanakh/competitive-rs | /src/display.rs | UTF-8 | 5,464 | 3.125 | 3 | [
"MIT"
] | permissive | use crate::gf::GF;
use std::{
any::{Any, TypeId},
fmt::{self, Display, Formatter},
};
pub struct Vertical<T>(pub Vec<T>);
impl<T> Into<Vertical<T>> for Vec<T> {
fn into(self) -> Vertical<T> {
Vertical(self)
}
}
pub struct Mat<T>(pub Vec<Vec<T>>);
impl<T> Into<Mat<T>> for Vec<Vec<T>> {
fn... | true |
350798404067df26a5358f13d69f7d40c6818c98 | Rust | timxor/payment-api | /src/bin/create_user.rs | UTF-8 | 2,495 | 3.015625 | 3 | [
"Apache-2.0"
] | permissive | extern crate diesel;
extern crate payment_api;
use std::process::Command;
use payment_api::*;
use std::io::{stdin, Read};
fn main() {
// todo call api here from main with a flag, import this file into main and call it like
// todo create_user.create_new_user(true, payload);
let access = false;
create_n... | true |
f0071a812dc99d112980818fc3f24635006f36ca | Rust | justahero/noire-rs | /src/renderer/src/pipeline/pipeline_layout.rs | UTF-8 | 2,049 | 2.9375 | 3 | [] | no_license | use std::collections::HashMap;
use crate::{BindGroupDescriptor, Shader, ShaderError, ShaderLayout, VertexBufferDescriptor};
#[derive(Debug)]
pub struct PipelineLayout {
/// The list of bind group descriptors
pub bind_groups: Vec<BindGroupDescriptor>,
/// The list of vertex buffer descriptors
pub verte... | true |
3b7be994d6181017650bed3913d0e3967e9dd75a | Rust | nushell/nushell | /crates/nu-command/src/generators/seq_date.rs | UTF-8 | 10,817 | 2.6875 | 3 | [
"MIT"
] | permissive | use chrono::naive::NaiveDate;
use chrono::{Duration, Local};
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned,
SyntaxShape, Type, Value,
};
#[der... | true |
43480ead46fe75e53d857f0cfbb7fa648cd62a29 | Rust | livexia/algorithm | /blind_75_leetcode/src/solution/s0125_valid_palindrome.rs | UTF-8 | 853 | 3.46875 | 3 | [] | no_license | #![allow(dead_code)]
pub struct Solution {}
impl Solution {
pub fn is_palindrome(s: String) -> bool {
let mut chars = s
.chars()
.filter(|c| c.is_alphanumeric())
.map(|c| c.to_ascii_uppercase());
while let (Some(a), Some(b)) = (chars.next(), chars.next_back()) {
... | true |
54ea4c2e98e4e9d8dec924b7f47139053a17d505 | Rust | InteractiveComputerGraphics/higher_order_embedded_fem | /simulation_toolbox/src/components/mod.rs | UTF-8 | 6,892 | 2.5625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use std::convert::TryInto;
use std::error::Error;
use std::fmt;
use std::fmt::{Debug, Display};
use coarse_prof::profile;
use fenris::nalgebra::{Vector2, Vector3};
use hamilton::storages::{ImmutableSingletonStorage, SingletonStorage, VecStorage};
use hamilton::{Component, FilterSystem, RunOnceSystem, StorageContainer,... | true |
82d7ae58c79e9b732efc599240384353fc20249e | Rust | AndreasOM/omt | /src/util/filehelper.rs | UTF-8 | 491 | 3.171875 | 3 | [
"MIT"
] | permissive | use std::fs::File;
use std::io::{BufRead, BufReader};
pub struct FileHelper {}
impl FileHelper {
pub fn lines_in_file(filename: &str) -> Result<Vec<String>, &'static str> {
let file = File::open(filename);
let file = match file {
Ok(p) => p,
Err(_e) => return Err("Error reading file"),
};
let bufread... | true |
307b9e4f919eec6acbb76873df4e028cc3217ec4 | Rust | woshilapin/advent-calendar | /2020/01_report-repair/src/main.rs | UTF-8 | 2,504 | 3.390625 | 3 | [] | no_license | use std::{
env,
fs::File,
io::{BufRead, BufReader},
};
#[cfg(not(feature = "three"))]
fn fix_expense_report(entries: &[u32]) -> (u32, u32) {
for (i, &expense1) in entries.iter().enumerate() {
for &expense2 in &entries[i..] {
if expense1 + expense2 == 2020 {
return (e... | true |
730428016484f9937e2e0464b39c2d163448d0cf | Rust | TianTianForever/Rust-Tutorial | /fifty_eight_days_of_rust/src/bin/main.rs | UTF-8 | 554 | 2.96875 | 3 | [] | no_license | use std::net::TcpListener;
use std::net::TcpStream;
extern crate fifty_eight_days_of_rust;
use fifty_eight_days_of_rust::ThreadPool;
fn handle_connection(stream: TcpStream){
// handle connection code.
}
fn main() {
let listener = TcpListener::bind("127.0.0.1:8080").unwrap();
// Create a thread pool with... | true |
f22d26409b0f9a2153dcd353c6e0e670dd7b0b96 | Rust | JaredShay/Popongong | /src/sounds.rs | UTF-8 | 1,174 | 3.171875 | 3 | [
"MIT"
] | permissive | use sdl2;
use std::path::Path;
use std::collections::HashMap;
#[derive(Debug)]
pub struct Sounds<'a> {
sounds: HashMap<String, sdl2::mixer::Music<'a>>
}
impl<'a> Sounds<'a> {
pub fn new() -> Sounds<'a> {
let mut sounds: HashMap<String, sdl2::mixer::Music> = HashMap::new();
for level in 1..4 ... | true |
04694310e0c969885a6622a8a50a39afedb9f239 | Rust | benfred/py-spy | /src/timer.rs | UTF-8 | 2,526 | 3.140625 | 3 | [
"MIT"
] | permissive | use std::time::{Duration, Instant};
#[cfg(windows)]
use winapi::um::timeapi;
use rand_distr::{Distribution, Exp};
/// Timer is an iterator that sleeps an appropriate amount of time between iterations
/// so that we can sample the process a certain number of times a second.
/// We're using an irregular sampling strate... | true |
14efbc6a0d521de7f4058b907bda5f083df48d79 | Rust | hacspec/hacspecs-rust | /src/poly1305.rs | UTF-8 | 2,362 | 2.59375 | 3 | [] | no_license | // Import hacspec and all needed definitions.
use hacspec::prelude::*;
// Import chacha20
use crate::chacha20;
use crate::chacha20::*;
const BLOCKSIZE: usize = 16;
// Type definitions for use in poly1305.
// These are type aliases for convenience
bytes!(Block, BLOCKSIZE);
// These are actual types; fixed-length arr... | true |
cef22ecafb3fef9b75ed0d2b2e845459fc735e59 | Rust | samyuyagati/dpcount | /src/dp_count_laplace.rs | UTF-8 | 1,849 | 3.28125 | 3 | [] | no_license | use std::f64;
use randomkit::dist::Laplace;
use randomkit::{Rng, Sample};
// Differentially-private count using the Laplace mechanism to add noise.
pub struct DPCounterLP {
epsilon: f64,
count: f64,
noise: f64,
count_updated: bool,
noise_distr: Laplace,
rng: Rng,
}
impl DPCounterLP {
pub fn... | true |
bd1d98e048979b3a6f37f8580ed4f15fa190572c | Rust | zhaohaijun/holochain-rust | /src/nucleus/mod.rs | UTF-8 | 1,140 | 2.75 | 3 | [] | no_license | pub mod dna;
pub mod ribosome;
use self::dna::DNA;
//use self::ribosome::*;
use state;
use std::rc::Rc;
#[derive(Clone, Debug)]
pub struct NucleusState {
dna: Option<DNA>,
inits: i32,
}
impl NucleusState {
pub fn create() -> Self {
NucleusState {
dna: None,
inits: 0,
... | true |
182c88ead97e37dd18203ad3ff0b6c62d4cf7d7d | Rust | yutiansut/sonnerie | /src/record.rs | UTF-8 | 837 | 2.921875 | 3 | [
"BSD-2-Clause",
"BSD-3-Clause"
] | permissive | use std::rc::Rc;
pub struct OwnedRecord
{
pub(crate) key_pos: usize,
pub(crate) key_len: usize,
pub(crate) fmt_pos: usize,
pub(crate) fmt_len: usize,
pub(crate) value_pos: usize,
pub(crate) value_len: usize,
pub(crate) data: Rc<Vec<u8>>,
}
impl OwnedRecord
{
pub fn key(&self) -> &str
{
let d = &self.data[s... | true |
9ef2c36858c6ed877502f458327720c2e2712f68 | Rust | OPeyrusse/project-tz-io | /rs-parser/src/samples.rs | UTF-8 | 2,074 | 3.125 | 3 | [
"MIT"
] | permissive | // use nom::{space, alphanumeric, multispace, is_alphanumeric, be_i32};
// // use nom::types::CompleteByteSlice;
// use nom::IResult;
// use std::result::Result;
// use std::{str,Utf8Error};
// // use std::collections::HashMap;
// fn take_wrapper(input: &[u8], i: u8) -> IResult<&[u8],&[u8]> {
// take!(input, i)
/... | true |
d76f1c1e789427f73f20130b8af82205b75e2eb8 | Rust | ferrous-systems/imxrt1052 | /src/pxp/ps_ctrl_set/mod.rs | UTF-8 | 21,037 | 2.53125 | 3 | [] | no_license | #[doc = r" Value read from the register"]
pub struct R {
bits: u32,
}
#[doc = r" Value to write to the register"]
pub struct W {
bits: u32,
}
impl super::PS_CTRL_SET {
#[doc = r" Modifies the contents of the register"]
#[inline]
pub fn modify<F>(&self, f: F)
where
for<'w> F: FnOnce(&R, &... | true |
046d9095a423cf2339cdeaaac069909290717cf4 | Rust | Phala-Network/phala-blockchain | /crates/phala-scheduler/src/request_scheduler.rs | UTF-8 | 16,055 | 2.671875 | 3 | [
"Apache-2.0"
] | permissive | use std::collections::HashMap;
use std::fmt::Debug;
use std::hash::Hash;
use std::sync::{Arc, Mutex, Weak};
use std::time::{Duration, Instant};
use rbtree::RBTree;
use thiserror::Error;
use tokio::sync::oneshot::{channel, Receiver, Sender};
pub type VirtualTime = u128;
pub trait FlowIdType: Clone + Send + Eq + Hash +... | true |
1c683f986d99cf297e1f0591856b9c1d597a11e6 | Rust | jaeh/rust-playground | /book/6/matches-option/src/main.rs | UTF-8 | 775 | 3.71875 | 4 | [] | no_license |
fn plus_one(x: Option<i32>) -> Option<i32> {
match x {
None => None,
Some(i) => Some(i + 1),
}
}
fn main() {
let five = Some(5);
let six = plus_one(five);
let none = plus_one(None);
println!("five {:#?}", five);
println!("six {:#?}", six);
println!("none {:#?}", none);... | true |
0ccd3daf84811d448661595ae3d452d66d55593f | Rust | drewet/gunship-rs | /lib/bootstrap_rs/src/linux/window.rs | UTF-8 | 575 | 2.78125 | 3 | [] | no_license | use std::rc::Rc;
use std::cell::RefCell;
use window::Message;
#[derive(Debug, Clone, Copy)]
pub struct Window;
impl Window {
pub fn new(_name: &str, _instance: ()) -> Rc<RefCell<Window>> {
println!("Window::new() is not implemented on linux");
Rc::new(RefCell::new(Window))
}
pub fn handl... | true |
1aedd106068777901b5d97168df4ea0b86930fd1 | Rust | hafifamudi/rust-guessing-game | /src/main.rs | UTF-8 | 1,166 | 3.96875 | 4 | [] | no_license | use rand::Rng;
use std::io;
use std::cmp::Ordering;
fn main() {
println!("Tebak Angka / Guess the number!");
//generate random number with rand library
//lower inclusif and upper ekslusif
let secret_number = rand::thread_rng().gen_range(1..101);
loop {
println!("Please input yout numbe... | true |
420437a72c9c9e3d6dcc6dec622342def47ff71b | Rust | OliverUv/rltk_rs | /bracket-random/src/parsing.rs | UTF-8 | 3,334 | 3.84375 | 4 | [
"MIT"
] | permissive | use regex::Regex;
use std::error;
use std::fmt;
// Describes a dice roll type
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct DiceType {
pub n_dice: i32,
pub die_type: i32,
pub bonus: i32,
}
impl DiceType {
pub fn new... | true |
1df6ffcfa9b3a7b6967c70baabb93bebabfe0722 | Rust | feng-qiu-dialog/git-rev | /src/exec.rs | UTF-8 | 2,576 | 3.125 | 3 | [
"MIT"
] | permissive | use std::process::Command;
use super::{Error, GitInfo};
pub fn git_info(tag_filter: &Option<String>, short: &Option<usize>) -> Result<GitInfo, Error> {
let rev = git_rev_parse()?;
let rev_short = git_rev_parse_short(short)?;
let branch = git_branch()?;
let tags = git_tags(tag_filter)?;
Ok(GitInfo... | true |
1a7b3c3d1465ba72dc3829757bad8d9fdb81e276 | Rust | agajews/web-crawler | /src/bin/domaintest.rs | UTF-8 | 331 | 2.671875 | 3 | [] | no_license |
fn domain_root(domain: &str) -> String {
let subdomains = domain.split('.').collect::<Vec<_>>();
subdomains[(subdomains.len() - 2)..].join(".")
}
fn main() {
println!("{}", domain_root("columbia.edu"));
println!("{}", domain_root("math.columbia.edu"));
println!("{}", domain_root("src.math.columbia... | true |
d2203d65304ba8df47cc50477ef0659e69f93be3 | Rust | nextsql/sql-parser | /src/literal/date.rs | UTF-8 | 903 | 2.625 | 3 | [
"MIT"
] | permissive | //in parser,we cannt valid the date format,
use nom::multispace;
use super::string::StringType;
use super::string::string_type;
pub enum DateTime<'a>{
Date(StringType<'a>),
Time(StringType<'a>),
Timestamp(StringType<'a>)
}
named!(date<&[u8],DateTime>,
do_parse!(
tag_no_case!("DATE") >>
... | true |
758a19b565d655e6896d104eb159a7470e8f2b11 | Rust | dsietz/test-data-generation | /examples/02_demo.rs | UTF-8 | 655 | 2.90625 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | extern crate test_data_generation;
use test_data_generation::data_sample_parser::DataSampleParser;
fn main() {
// This example demonstrates the basic feature of the library to generate dates and people's names from a CSV file
// using sample data that is included in the library.
// initalize a new DataSa... | true |
434cb266cb04aee93feaf75d108b9867cf4cba19 | Rust | iterate/counters-backend | /src/main.rs | UTF-8 | 1,604 | 2.671875 | 3 | [] | no_license | #![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
extern crate rocket_contrib;
use std::collections::HashMap;
use std::sync::Mutex;
use rocket_contrib::Json;
use rocket::State;
use rocket::fairing::AdHoc;
type Counters = Mutex<HashMap<String, i32>>;
#[get("/counters")]
fn get_counters(counters: S... | true |
ef50d2237c798fd8536478df5aca18bd86251380 | Rust | janpauldahlke/fhir-rs | /src/model/Bundle_Response.rs | UTF-8 | 9,944 | 3 | 3 | [
"MIT"
] | permissive | #![allow(unused_imports, non_camel_case_types)]
use crate::model::Element::Element;
use crate::model::Extension::Extension;
use crate::model::ResourceList::ResourceList;
use serde_json::json;
use serde_json::value::Value;
use std::borrow::Cow;
/// A container for a collection of resources.
#[derive(Debug)]
pub struc... | true |
49cb9fb693b728e73a665c2b84270e426157a60e | Rust | sbnair/farkle-rs | /src/player.rs | UTF-8 | 569 | 3.3125 | 3 | [
"MIT"
] | permissive | use std::fmt;
pub struct Player {
name: String,
score: u16,
}
impl Player {
pub fn new(player_name: &str) -> Player {
Player {
name: player_name.to_string(),
score: 0,
}
}
pub fn on_board(&self) -> bool {
self.score >= 500
}
pub fn scor... | true |
e5836c65d7b4b775174dd5d8d2889eff9ad8fcf4 | Rust | Jkillelea/game_of_life | /src/main.rs | UTF-8 | 6,125 | 2.875 | 3 | [] | no_license | // A simple Game of Life implementation. Copyright Jacob Killelea
// Will otherwise throw warnings because of conditional compilation skipping
// certain functions
#![allow(unused)]
extern crate rand;
#[cfg(feature = "opencl")]
extern crate ocl;
extern crate png;
extern crate rayon;
use rayon::prelude::*;
use std:... | true |
6401b2c1c362a4df167c8a7a241b519c59b44cc8 | Rust | himlpplm/rust-tdlib | /src/types/get_map_thumbnail_file.rs | UTF-8 | 3,237 | 2.90625 | 3 | [
"MIT"
] | permissive | use crate::errors::*;
use crate::types::*;
use uuid::Uuid;
/// Returns information about a file with a map thumbnail in PNG format. Only map thumbnail files with size less than 1MB can be downloaded
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct GetMapThumbnailFile {
#[doc(hidden)]
#[serde... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.