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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
7854f0d243425d917f19d5b06fb07b00e228a64a | Rust | SnoozeTime/game-off-2019 | /src/states/gameover.rs | UTF-8 | 3,391 | 3.046875 | 3 | [] | no_license | use crate::{
event::{AppEvent, MyEvent},
states::MyTrans,
util::delete_hierarchy,
};
use amethyst::{
ecs::prelude::Entity,
input::{is_close_requested, is_key_down},
prelude::*,
ui::{UiCreator, UiEvent, UiEventType, UiFinder},
winit::VirtualKeyCode,
};
use log::info;
const RETRY_BUTTON_I... | true |
cae742176261447b0c1a2ff334fe9f14c465df71 | Rust | cocagne/aspen-server | /src/crl/sweeper/log_file.rs | UTF-8 | 14,047 | 2.625 | 3 | [] | no_license | use std::collections::{HashMap, HashSet};
use std::fmt;
use std::ffi::CString;
use std::io::{Result, Error, ErrorKind};
use std::os::unix::ffi::OsStrExt;
use std::path::{Path, PathBuf};
use libc;
use log::{error, info, warn};
use crate::{Data, ArcDataSlice};
use super::*;
pub(super) struct LogFile {
file_path: ... | true |
cd010b754bd21998db42eedafe1721e592bca7ca | Rust | zaeleus/noodles | /noodles-bam/src/lazy/record/cigar.rs | UTF-8 | 1,097 | 2.671875 | 3 | [
"MIT"
] | permissive | use std::io;
use noodles_sam as sam;
/// Raw BAM record CIGAR operations.
#[derive(Debug, Eq, PartialEq)]
pub struct Cigar<'a>(&'a [u8]);
impl<'a> Cigar<'a> {
pub(super) fn new(src: &'a [u8]) -> Self {
Self(src)
}
/// Returns whether there are any CIGAR operations.
pub fn is_empty(&self) -> ... | true |
7e266acac341196b63ca004e859f739310f9aca1 | Rust | zeta1999/titik | /src/widget/image_control.rs | UTF-8 | 2,075 | 3.140625 | 3 | [
"MIT"
] | permissive | use crate::{
buffer::Buffer,
widget::traits::ImageTrait,
Cmd,
LayoutTree,
Widget,
};
use image::{
self,
DynamicImage,
};
use std::{
any::Any,
fmt,
marker::PhantomData,
};
use stretch::style::Style;
/// Image widget, supported formats: jpg, png
pub struct Image<MSG> {
image: ... | true |
221abfa7d36998dcdf0fed4b4e38b3c378632c0b | Rust | mattiasgronlund/cubemx-db-decoder | /src/cubemx_db/ip/bsp_dependency.rs | UTF-8 | 1,710 | 2.890625 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use super::Condition;
use crate::{
decode::{AttributeMap, Decode},
error::Unexpected,
Config, Error,
};
#[derive(Debug)]
pub struct BspDependency {
pub name: String,
pub comment: String,
pub bsp_ip_name: String,
pub bsp_mode_name: Option<String>,
pub user_name: Option<String>,
pub a... | true |
94559e67a219d06cf3409cb5cd5b8878ca6f99e4 | Rust | rust-lang/rustfmt | /tests/source/cfg_if/detect/os/freebsd/auxvec.rs | UTF-8 | 2,795 | 2.796875 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Parses ELF auxiliary vectors.
#![cfg_attr(any(target_arch = "arm", target_arch = "powerpc64"), allow(dead_code))]
/// Key to access the CPU Hardware capabilities bitfield.
pub(crate) const AT_HWCAP: usize = 25;
/// Key to access the CPU Hardware capabilities 2 bitfield.
pub(crate) const AT_HWCAP2: usize = 26;
///... | true |
76ef40415e911edbaeac5c53ffd27e73fae782fe | Rust | seanjensengrey/rust-copperline | /src/run.rs | UTF-8 | 3,187 | 3.25 | 3 | [
"MIT"
] | permissive | use error::Error;
use edit::{EditCtx, EditResult, edit};
use builder::Builder;
use parser::{parse_cursor_pos, ParseError, ParseSuccess};
pub trait RunIO {
fn write(&mut self, Vec<u8>) -> Result<(), Error>;
fn read_byte(&mut self) -> Result<u8, Error>;
fn prompt(&mut self, w: Vec<u8>) -> Result<u8, Error>... | true |
b457c3384046d00e733c9e51404764c445d0053d | Rust | schell/todo_finder | /todo_finder_lib/src/parser.rs | UTF-8 | 11,540 | 2.890625 | 3 | [
"MIT"
] | permissive | use nom::{bytes::complete as bytes, character::complete as character, combinator, IResult};
use super::{
finder::FileSearcher,
github::{GitHubIssue, GitHubPatch},
};
use serde::Deserialize;
use std::{collections::HashMap, fs::File, io::prelude::*, path::Path};
pub mod issue;
pub mod langs;
pub mod source;
us... | true |
190c6d70bc4a674d56a1a39ad3ac39e9ecf2a32a | Rust | gaotianyu1350/rCore_audio | /crate/thread/src/scheduler/o1.rs | UTF-8 | 1,673 | 3.484375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! O(1) scheduler introduced in Linux 2.6
//!
//! Two queues are maintained, one is active, another is inactive.
//! Take the first task from the active queue to run. When it is empty, swap active and inactive queues.
use super::*;
pub struct O1Scheduler {
inner: Mutex<O1SchedulerInner>,
}
struct O1SchedulerInn... | true |
be1f3ec769de5dda41154a14246a8370e7bd9a90 | Rust | arosspope/advent-of-code | /aoc_2020/src/day2.rs | UTF-8 | 1,771 | 3.4375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //Day 2: Password Philosophy
//
#[derive(Debug, PartialEq)]
pub struct PasswordPolicy {
character: char,
max: usize,
min: usize,
}
#[derive(Debug, PartialEq)]
pub struct PasswordEntry {
policy: PasswordPolicy,
password: String
}
#[aoc_generator(day2)]
pub fn input_passwords(input: &str) -> Vec<P... | true |
2d8843b4a2f5d130c42e3d83cc0b3513518d4cff | Rust | frehberg/rtps-rs | /src/structure/locator_kind.rs | UTF-8 | 1,296 | 2.53125 | 3 | [
"Apache-2.0"
] | permissive | #[derive(Clone, Debug, Eq, PartialEq, Readable, Writable)]
pub struct LocatorKind_t {
value: i32,
}
impl LocatorKind_t {
pub const LOCATOR_KIND_INVALID: LocatorKind_t = LocatorKind_t { value: -1 };
pub const LOCATOR_KIND_RESERVED: LocatorKind_t = LocatorKind_t { value: 0 };
pub const LOCATOR_KIND_UDPv4... | true |
0e12ee80148bc53d228c2e684528c76a5f20dc7b | Rust | tjni/offstage | /tests/repository.rs | UTF-8 | 2,535 | 3 | 3 | [
"Apache-2.0"
] | permissive | use anyhow::{anyhow, Result};
use git2::{Commit, ErrorCode, Repository, Signature};
use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::slice;
pub const README: &str = "README";
pub const LICENSE: &str = "LICENSE";
pub struct TestRepository {
repository: Repository,
}
impl TestReposit... | true |
bfd8e04a874ea866f13cc650c980f72c1b70bda9 | Rust | jjgz/server | /src/net.rs | UTF-8 | 13,740 | 3.03125 | 3 | [] | no_license | use std::io::{Read, Write};
use std::sync::mpsc::{channel, TryRecvError, Sender};
use std::time;
use std::sync::{Mutex, Arc};
use std::thread;
use std::net::TcpStream;
use serde_json;
use rnet::Netmessage;
struct Crc8 {
crc: u16,
}
impl Crc8 {
fn new() -> Crc8 {
Crc8 { crc: 0 }
}
fn add_byt... | true |
b898a0f053240a76a48f9fc04b601b28e3b8f7c0 | Rust | CoiroTomas/voronoi | /src/main.rs | UTF-8 | 3,844 | 2.578125 | 3 | [
"MIT"
] | permissive | #![windows_subsystem = "windows"]
extern crate piston;
extern crate piston_window;
extern crate image;
use piston_window::*;
use std::path::Path;
static COLOURS : [[u8;4]; 16] = [[255, 255, 255, 255], [0, 255, 255, 255], [255, 0, 255, 255], [255, 255, 0, 255],
[192, 192, 192, 255], [255, 0, 0, 255], [0, 255, 0, ... | true |
aff514c685d46defd045eda63d0fb352c62c93e5 | Rust | bouzuya/rust-atcoder | /cargo-atcoder/contests/past202010-open/src/bin/d.rs | UTF-8 | 699 | 3.015625 | 3 | [] | no_license | use proconio::input;
use proconio::marker::Chars;
use std::cmp::max;
fn main() {
input! {
n: usize,
s: Chars,
};
let mut counts = vec![0];
for i in 0..n {
match s[i] {
'.' => {
let l = counts.len();
counts[l - 1] += 1;
}
... | true |
d8c581f00820fad6ad4b850d72e6990e9b8e4767 | Rust | aticu/pre | /proc-macro/src/extern_crate.rs | UTF-8 | 11,093 | 2.859375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! Provides handling of `extern_crate` attributes.
//!
//! # What the generated code looks like
//!
//! ```rust,ignore
//! #[pre::extern_crate(std)]
//! mod pre_std {
//! mod ptr {
//! #[pre(valid_ptr(src, r))]
//! unsafe fn read<T>(src: *const T) -> T;
//!
//! impl<T> NonNull<T> {
//! ... | true |
c3e7161eb645b6b2524066710a7d016f7b2a007e | Rust | chroussel/hdfs-cli | /walk/src/err.rs | UTF-8 | 575 | 2.625 | 3 | [] | no_license | #[derive(Debug)]
pub enum Error {
IoError(std::io::Error),
PathConversionError(std::ffi::OsString),
PatternError(glob::PatternError),
NoPathDefined,
PathFormatError,
}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Error::IoError(err)
}
}
impl From<std... | true |
d53362f508c65b559b3470a0f8eab72975f99112 | Rust | AntonGepting/tmux-interface-rs | /src/formats/formats_output.rs | UTF-8 | 46,302 | 2.59375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use super::VariableOutput;
#[cfg(feature = "tmux_2_5")]
use crate::SessionStack;
#[cfg(feature = "tmux_1_6")]
use crate::{Layout, PaneTabs, WindowFlags};
#[derive(Debug)]
pub struct FormatsOutput<'a> {
pub separator: char,
pub variables: Vec<VariableOutput<'a>>,
}
impl<'a> Default for FormatsOutput<'a> {
... | true |
a67a875f18fff072f6a98e8e3f032f1ae6188089 | Rust | azriel91/autexousious | /crate/game_input_model/src/loaded/control_axis.rs | UTF-8 | 441 | 2.796875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | use strum_macros::{Display, EnumIter, EnumString};
/// Control axis input for characters.
///
/// This is not used in `PlayerInputConfigs`, but as a logical representation
#[derive(Clone, Copy, Debug, Display, EnumIter, EnumString, Hash, PartialEq, Eq)]
#[strum(serialize_all = "snake_case")]
pub enum ControlAxis {
... | true |
a936a09f5d895b5afde9355857431cb9846f79b7 | Rust | michaelfletchercgy/rainguage | /rainguage-messages/src/lib.rs | UTF-8 | 10,872 | 2.65625 | 3 | [] | no_license | #![no_std]
use serde::{Serialize, Deserialize};
use crc::{crc32, Hasher32};
use core::iter::Iterator;
use byteorder::ByteOrder;
use byteorder::NetworkEndian;
const MAGIC:[u8;3] = [125, 8, 141];
#[derive(Debug)]
pub enum SerializeError {
Internal(postcard::Error)
}
impl From<postcard::Error> for SerializeError ... | true |
c96ffdf4ce028903abd2c5f8f8af36bd4802a0fe | Rust | lwandsyj/rust | /lear2/src/fn_learn.rs | UTF-8 | 457 | 3.640625 | 4 | [] | no_license | pub fn test(mut a: i32) -> i32 {
a = a + 1;
a
}
pub fn test_brow(a: &mut i32) -> i32 {
*a = *a + 1;
*a
}
/**
* 调用
* let mut a = 1;
let b = test_brow(&mut a);
println!("{}", a);
println!("{}", b);
*/
// 引用类型数组可以是不固定长度
fn test1(a:&[i32]){
println!("{:?}",a);
}
fn main1() {
let... | true |
fa48ace6d44158d05469e73fe64e130b9a9d89bf | Rust | vinhhungle/webassembly-react | /rust-wasm/src/condition.rs | UTF-8 | 345 | 3.21875 | 3 | [] | no_license | pub fn run() {
let age: u8 = 18;
let is_of_age = age >= 21; // if age >= 21 { true } else { false }
let check_id: bool = false;
if is_of_age && check_id {
println!("What would you like to drink?")
} else if !is_of_age && check_id {
println!("Sorry, you have to leave")
} else {
println!("I'll ne... | true |
f882a7f4a73e5e42c780f1c2ad2861aebf7630de | Rust | a-bakos/rust-playground | /archived-learning/hands-on-data-structures-and-algorithms-in-rust/p03-copy-clone-mut/src/main.rs | UTF-8 | 484 | 3.796875 | 4 | [] | no_license | // i32 implements Copy marker trait
// it means it'll automatically copy all of the memory across
#[derive(Debug, Clone)]
pub struct Person {
name: String,
age: i32,
}
fn main() {
let p = Person {
name: "Frank".to_string(),
age: 6,
};
// if the struct doesn't have a clone marker t... | true |
32b2d5090f408320f38da66b0cafd85473979f43 | Rust | RussellChamp/advent-of-code-2016 | /2016/day18/src/main.rs | UTF-8 | 3,519 | 3.328125 | 3 | [
"MIT"
] | permissive | // Trap rules
// * if 110 or 011, 100, 001
// where nonexistent sides are considered 0
#[derive(Debug, PartialEq, Clone)]
enum Tile {
Trapped = 1,
Safe = 0
}
type Row = Vec<Tile>;
type Grid = Vec<Row>;
//Part 1
fn add_row(grid: &mut Grid) {
static TRAPS: [[Tile; 3]; 4] =
[
[Tile::Trapped, Ti... | true |
545012f4c355fa241565f3f8a3c323a1d4a9ff88 | Rust | bokutotu/curs | /src/error.rs | UTF-8 | 4,563 | 2.765625 | 3 | [] | no_license | use cublas_sys::cublasStatus_t;
use cuda_runtime_sys::cudaError_t;
use std::ffi::CStr;
use std::fmt::{self, Debug, Display, Formatter, Result};
use std::result;
use thiserror::Error;
pub struct CublasError {
pub raw: cublasStatus_t,
}
fn cublas_error_to_string(error: cublasStatus_t) -> String {
let string =... | true |
ba5f9e5f0e0e9f5dfc7aae99bdb8e3f4bff64182 | Rust | gkbrk/rust-gophermap | /src/lib.rs | UTF-8 | 7,404 | 3.484375 | 3 | [
"MIT"
] | permissive | //! gophermap is a Rust crate that can parse and generate Gopher responses.
//! It can be used to implement Gopher clients and servers. It doesn't handle
//! any I/O on purpose. This library is meant to be used by other servers and
//! clients in order to avoid re-implementing the gophermap logic.
//!
#![forbid(unsafe_... | true |
2b767f69ea875614b833ec9e1a0a3fd6e55c467f | Rust | lRiaXl/public | /rust/tests/handling_test/src/main.rs | UTF-8 | 1,518 | 3.03125 | 3 | [] | no_license | use std::fs::{File, OpenOptions};
use std::io::prelude::*;
use std::io::{ErrorKind, Write};
use handling::*;
fn main() {
let path = "a.txt";
File::create(path).unwrap();
open_or_create(path, "content to be written");
let mut file = File::open(path).unwrap();
let mut s = String::new();
file.re... | true |
853818ae4a5022d99e5f1716821e20633639d1d7 | Rust | loganyu/leetcode | /problems/039_combination_sum.rs | UTF-8 | 1,751 | 3.375 | 3 | [] | no_license | /*
Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order.
The same number may be chosen from candidates an unlimited number of times. Two combinations are un... | true |
9764428f58e3b7115da7f14af1e85b665bf17c63 | Rust | rennis250/processing-rs | /src/transform.rs | UTF-8 | 5,690 | 3.109375 | 3 | [] | no_license | use Screen;
use {Matrix4, Vector3, Unit};
impl<'a> Screen<'a> {
/// Pre-multiply the current MVP transformation matrix with a matrix formed
/// from the given values.
pub fn apply_matrix(
&mut self,
n00: f32,
n01: f32,
n02: f32,
n03: f32,
n10: f32,
n11: f3... | true |
12d236367ef244f322b7b6bd11d856b60a1b6374 | Rust | fplust/rlox | /src/main.rs | UTF-8 | 1,939 | 2.578125 | 3 | [] | no_license | mod error;
mod expr;
mod parser;
mod scanner;
mod token;
mod tokentype;
// mod ast_printer;
mod environment;
mod interpreter;
mod lox_class;
mod lox_function;
mod lox_instance;
mod object;
mod resolver;
mod stmt;
// use crate::ast_printer::AstPrinter;
use crate::interpreter::Interpreter;
use crate::parser::Parser;
use ... | true |
b5af8f9041f17ae6b77bc3f6bf4ef7176e48d52d | Rust | tramulns/benchmark-memory | /benchmark_cpu_cache_levels/src/lib.rs | UTF-8 | 1,057 | 2.65625 | 3 | [] | no_license | #![feature(test)]
#[allow(dead_code)]
const KB: usize = 1024;
#[allow(dead_code)]
const MB: usize = KB * KB;
#[allow(dead_code)]
const N: usize = 16 * MB;
#[cfg(test)]
mod tests {
use super::*;
extern crate test;
use test::Bencher;
#[bench]
fn bench_calc_2048kb_array(b: &mut Bencher) {
... | true |
be21e70db1ad07f2956d7930c5810a9072dc93d3 | Rust | sb89/fixerio | /src/exchange.rs | UTF-8 | 5,318 | 3.125 | 3 | [
"MIT"
] | permissive | /// The response from fixerio.
#[derive(Debug, Deserialize)]
pub struct Exchange {
/// The base currency requested.
pub base: String,
/// The date for which the exchange rates are for.
pub date: String,
/// The exhcange rates for the base currency.
pub rates: Rates,
}
/// The exchange rates for... | true |
d6bce0e50164ea12f0582d985617da83d365deac | Rust | hhawkens/advent_2018 | /src/day_3/types.rs | UTF-8 | 307 | 3.125 | 3 | [] | no_license | #[derive(Debug)]
pub struct Rect {
pub location: Point,
pub size: Size,
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct Point {
/// To the right
pub x: i32,
/// Down
pub y: i32,
}
#[derive(Debug)]
pub struct Size {
/// Width
pub w: i32,
/// Height
pub h: i32,
}
| true |
19fe4a2a4dc0b8b479741fd7b037a5f5a86ff35f | Rust | popovegor/codeforces | /828B/rust/src/main.rs | UTF-8 | 1,572 | 2.9375 | 3 | [] | no_license | fn main() {
use std::io;
use std::io::prelude::*;
use std::cmp;
let stdin = io::stdin();
let mut counter = 0;
let mut w = 0;
let mut h = 0;
let (mut left, mut right, mut bottom, mut top) = (100,1,1,100);
let mut black_counter = 0;
let mut white_counter = 0;
for line in stdin.lock().lines() {
if coun... | true |
deaa1dd2e72f9a3791c19761bbbeab576028b47b | Rust | TheButlah/mujoco-rs | /mujoco/src/lib.rs | UTF-8 | 3,918 | 2.5625 | 3 | [
"MIT"
] | permissive | //! Provides safe bindings to [MuJoCo](http://www.mujoco.org/index.html), a physics
//! simulator commonly used for robotics and machine learning.
pub mod model;
mod re_exports;
pub mod state;
mod vfs;
pub use model::Model;
pub use state::State;
use lazy_static::lazy_static;
use std::cell::RefCell;
use std::ffi::{CS... | true |
5eb7cb64fc6ada724c5cb5ad419eb06d0161abad | Rust | chinatsu/oo-workshop | /src/chance/chance_test.rs | UTF-8 | 2,401 | 3.09375 | 3 | [] | no_license | use super::{Chance, ChanceError};
lazy_static! {
static ref CERTAIN: Chance = Chance::new(super::CERTAIN).unwrap();
static ref LIKELY: Chance = Chance::new(0.75).unwrap();
static ref FIFTY_NINE: Chance = Chance::new(0.59).unwrap();
static ref EQUALLY_LIKELY: Chance = Chance::new(0.5).unwrap();
stat... | true |
c39148bf9a189c3f29f336de12cf1d4b50c29ccc | Rust | rk9109/sandbox-api | /src/main.rs | UTF-8 | 494 | 2.546875 | 3 | [] | no_license | // TODO convert to REST API
mod command;
mod sandbox;
use command::Language;
use sandbox::Sandbox;
const TEST_C_CODE: &'static str = r#"
#include <stdio.h>
int main() {
for (int i = 0; i < 10; i++) {
printf("%d\n", i);
}
return 0;
}
"#;
fn main() {
let output = Sandbox::new(TEST_C_CODE, Lang... | true |
ac35012aa407d9854482267fa63f9b93b3688bba | Rust | akovaski/AdventOfCode | /2018/src/year2018/d10p1.rs | UTF-8 | 3,215 | 3.03125 | 3 | [] | no_license | use regex::Regex;
use std::cmp;
use std::collections::{HashSet, VecDeque};
use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
pub struct Light {
pub pos: Vector,
pub vel: Vector,
}
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
pub struct Vector {
pub x: i32,
pub y: i32,
}
... | true |
97da531d9ce4814033a7e71857f6c08bc0d22b83 | Rust | Indy2222/introns | /preprocess/src/samples/io.rs | UTF-8 | 6,475 | 2.75 | 3 | [] | no_license | use crate::features::FeatureId;
use anyhow::{Context, Error, Result};
use ncrs::data::Symbol;
use ndarray::{arr0, Array, Array2};
use ndarray_npy::NpzWriter;
use std::convert::TryFrom;
use std::fs::{self, File, OpenOptions};
use std::path::{Path, PathBuf};
pub struct OrganismWriter {
target_dir: PathBuf,
count... | true |
bd343b0c2338bee0b60f4e0baa7c43e2e41e35db | Rust | NyxTo/Advent-of-Code | /2019/Code/day_10_asteroid.rs | UTF-8 | 1,473 | 2.921875 | 3 | [] | no_license | use std::fs::File;
use std::io::{BufRead, BufReader};
use std::cmp::{min, max};
fn gcd(mut a: usize, mut b: usize) -> usize {
while b > 0 {
let rem = a % b;
a = b;
b = rem;
}
a
}
fn main() {
let grid = BufReader::new(File::open("in_10.txt").unwrap()).lines().map(|row| row.unwrap().chars().coll... | true |
fb77b7aa24d2d3bd97c7f147c149665782414c1d | Rust | algon-320/mandarin | /kernel/src/global.rs | UTF-8 | 1,247 | 2.546875 | 3 | [] | no_license | use crate::console::{Attribute, Console};
use crate::graphics::{font, FrameBuffer, Scaled};
use crate::sync::spin::SpinMutex;
use core::mem::MaybeUninit;
pub static FRAME_BUF: SpinMutex<MaybeUninit<Scaled<FrameBuffer, 1>>> =
SpinMutex::new("frame_buffer", MaybeUninit::uninit());
pub fn init_frame_buffer(frame_bu... | true |
ca3b5872214906c728258dca015c36f1abc89c86 | Rust | rob-clarke/arusti | /arusti/tests/olan_tests.rs | UTF-8 | 4,264 | 3.0625 | 3 | [] | no_license | use arusti;
use arusti::{ElementType,Element};
fn compare_elements(result: &Vec<Element>, expectation: &Vec<Element>) {
assert_eq!(result.len(), expectation.len(), "Figure has wrong number of elements");
for (index,(result,expected)) in result.iter().zip( expectation.iter() ).enumerate() {
assert_eq!(... | true |
04b6bedbfb90e194343d2fd56500d851e2843422 | Rust | m-lima/advent-of-code-2020 | /src/bin/112/build.rs | UTF-8 | 814 | 2.625 | 3 | [] | no_license | pub fn prepare() {
use std::io::Write;
const OUTPUT: &str = "src/bin/112/input.rs";
const INPUT: &str = include_str!("input.txt");
println!("cargo:rerun-if-changed=src/bin/112/{}", INPUT);
let input: Vec<_> = INPUT
.split('\n')
.filter(|line| !line.is_empty())
.map(|line| l... | true |
1f1bd79e8d27d676bd719d96aaa3a92ee51c7b2e | Rust | longlb/exercism | /rust/triangle/src/lib.rs | UTF-8 | 987 | 3.578125 | 4 | [] | no_license | pub struct Triangle {
side1: u64,
side2: u64,
side3: u64,
}
impl Triangle {
pub fn build(sides: [u64; 3]) -> Option<Triangle> {
let new_tri = Triangle {
side1: sides[0],
side2: sides[1],
side3: sides[2],
};
if new_tri.is_valid() {
... | true |
e393954bde0ff61b876070ee5572e15717893ce3 | Rust | acohen4/steelmate | /src/lib/engine.rs | UTF-8 | 13,224 | 3.15625 | 3 | [] | no_license | use super::board::{Board, Color, Piece, PieceKind, Position};
use std::collections::HashMap;
struct MovePattern {
is_repeatable: bool,
move_enumerations: Vec<Position>,
}
impl MovePattern {
fn new(is_repeatable: bool, move_enumerations: Vec<Position>) -> MovePattern {
MovePattern {
is_... | true |
b36f1451cae914f0eea9f2760d6377ec041aed44 | Rust | yaozijian/RustProgramming | /chap15/src/section1.rs | UTF-8 | 667 | 3.71875 | 4 | [
"MIT"
] | permissive | pub fn demo(){
let x = 5;
let y = &x;
let z = Box::new(x);
assert_eq!(x,5);
assert_eq!(*y,5);
assert_eq!(*z,5);
}
pub fn demo2(){
struct MyBox<T>(T);
impl<T> MyBox<T>{
fn new(x: T) -> MyBox<T>{
MyBox(x)
}
}
use std::ops::Deref;
impl<T> Deref for MyBox<T>{
type Target = T;
... | true |
0aed52d6d235a63d94a9e35e41fca828a0307f8a | Rust | zhengrenzhe/nand2tetris | /compiler/vm-compiler/src/lexical.rs | UTF-8 | 1,670 | 3.4375 | 3 | [] | no_license | #[derive(Debug)]
pub struct Token {
pub command: String,
pub target: String,
pub arg: String,
}
pub fn lexical(code: &str) -> Option<Token> {
let parts: Vec<&str> = code.split(' ').filter(|code| !code.is_empty()).collect();
if parts.is_empty() {
return None;
}
Some(Token {
... | true |
68d2c48e7b995f9cf69a985eb6292ef8c6ee5112 | Rust | chyvonomys/serpanok | /src/format.rs | UTF-8 | 5,990 | 2.765625 | 3 | [] | no_license | use chrono::{Datelike, Timelike};
pub fn format_lat_lon(lat: f32, lon: f32) -> String {
format!("{:.03}°{} {:.03}°{}",
lat.abs(), if lat > 0.0 {"N"} else {"S"},
lon.abs(), if lat > 0.0 {"E"} else {"W"},
)
}
const MONTH_ABBREVS: [&str; 12] = [
"Січ", "Лют", "Бер", "Кві", "Тра", "Чер... | true |
b16142cf5144097229d0a02f2e7942b78db3a226 | Rust | mcmcgrath13/delf-rs | /src/graph/mod.rs | UTF-8 | 10,170 | 3 | 3 | [
"MIT"
] | permissive | use std::collections::{HashMap, HashSet};
use std::process::exit;
use ansi_term::Colour::{Red, Green, Cyan};
use petgraph::{
graph::{EdgeIndex, NodeIndex},
Directed, Graph, Incoming, Outgoing,
};
/// The edge of a DelfGraph is a DelfEdge
pub mod edge;
/// The node of a DelfGraph is a DelfObject
pub mod object... | true |
6c0e8e36b308ca708bae70153efefedd172f86a1 | Rust | DesmondWillowbrook/cargo-optional-features-for-testing-and-examples | /src/main.rs | UTF-8 | 316 | 2.96875 | 3 | [] | no_license | use test_features::one::add_one;
#[cfg(feature = "add_two")]
use test_features::two::add_two;
fn main () -> std::io::Result<()> {
let num: usize = 5;
println!("Add 1 to num: {}", add_one(num));
#[cfg(feature = "add_two")]
{
println!("Add 2 to num: {}", add_two(num));
}
Ok(())
}
| true |
c844b05ad06a8c4daa911b893ebd4d3d01a64450 | Rust | schungx/rhai | /tests/debugging.rs | UTF-8 | 2,320 | 2.96875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #![cfg(feature = "debugging")]
use rhai::{Engine, INT};
#[cfg(not(feature = "no_index"))]
use rhai::Array;
#[cfg(not(feature = "no_object"))]
use rhai::Map;
#[test]
fn test_debugging() {
let mut engine = Engine::new();
engine.register_debugger(
|_, dbg| dbg,
|_, _, _, _, _| Ok(rhai::debugger... | true |
1921912b6e8472305a883f1d2b93b569d281c1c7 | Rust | ssolaric/cses.fi | /2. Sorting and Searching/7-sum-of-two-values.rs | UTF-8 | 1,696 | 3.3125 | 3 | [
"MIT"
] | permissive | // This is the 2sum problem.
use std::collections::HashMap;
use std::io;
use std::str;
pub struct Scanner<R> {
reader: R,
buffer: Vec<String>,
}
impl<R: io::BufRead> Scanner<R> {
pub fn new(reader: R) -> Self {
Self {
reader,
buffer: vec![],
}
}
pub fn toke... | true |
0231e78af7a2c964807b586b2b572d0e445cdd36 | Rust | UnicodeSnowman/matasano-crypto-challenges | /rust/src/main.rs | UTF-8 | 1,502 | 2.90625 | 3 | [] | no_license | extern crate matasano;
use matasano::one;
use matasano::two;
fn main() {
println!("{}", "Section One");
println!("{}", "================");
//one::convert_hex_to_base64("49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d");
//one::fixed_xor();
//let ... | true |
e4c3abce32634160b79e30513b200d65573cb2d5 | Rust | Palmr/lameboy | /src/lameboy/cpu/instructions/stack.rs | UTF-8 | 1,350 | 3.25 | 3 | [
"MIT"
] | permissive | use crate::lameboy::cpu::Cpu;
/// Push an 8-bit value to the stack.
/// Decrements the stack pointer and then writes the 8-bit value using the new stack pointer value.
pub fn push_stack_d8(cpu: &mut Cpu, d8: u8) {
// Decrement stack pointer
cpu.registers.sp = cpu.registers.sp.wrapping_sub(1);
// Write byt... | true |
d8c93dcd1e1c57d800375b0cc53edfdc80aafdc8 | Rust | feds01/lang | /compiler/hash-reporting/src/errors.rs | UTF-8 | 1,408 | 2.953125 | 3 | [
"MIT"
] | permissive | //! Hash Compiler error and warning reporting module
//!
//! All rights reserved 2021 (c) The Hash Language authors
use std::{io, process::exit};
use thiserror::Error;
use hash_ast::error::ParseError;
/// Enum representing the variants of error that can occur when running an interactive session
#[derive(Error, Debug... | true |
a7b9e243d738716f575b35969fd85aa122dd714c | Rust | immunant/c2rust | /c2rust-bitfields-derive/src/lib.rs | UTF-8 | 8,743 | 2.65625 | 3 | [
"BSD-3-Clause",
"Apache-2.0"
] | permissive | #![recursion_limit = "512"]
use proc_macro::{Span, TokenStream};
use quote::quote;
use syn::parse::Error;
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::{
parse_macro_input, Attribute, Field, Fields, Ident, ItemStruct, Lit, Meta, NestedMeta, Path,
PathArguments, PathSegment, Token,
};
#[... | true |
b8df6ae8e4de33703de889d4f76f010bd7c789e5 | Rust | stkfd/rd-histogram | /src/simple_vec_histogram.rs | UTF-8 | 6,022 | 3.125 | 3 | [] | no_license | use num::traits::NumAssign;
use ord_subset::{OrdSubset, OrdSubsetIterExt, OrdSubsetSliceExt};
use std::cmp::Ordering;
use traits::{DynamicHistogram, EmptyClone, Merge, MergeRef};
#[derive(Clone, Debug, PartialEq)]
pub struct SimpleVecHistogram<V, C> {
bins: Vec<Bin<V, C>>,
bins_cap: usize,
}
#[derive(Clone, D... | true |
c0563791dd9ae4d6ca09b42b63a69f0273affb6d | Rust | emakryo/cmpro | /src/abc221/src/bin/c.rs | UTF-8 | 885 | 2.59375 | 3 | [] | no_license | #![allow(unused_macros, unused_imports)]
use proconio::marker::Bytes;
macro_rules! dbg {
($($xs:expr),+) => {
if cfg!(debug_assertions) {
std::dbg!($($xs),+)
} else {
($($xs),+)
}
}
}
fn main() {
proconio::input!{
n: Bytes,
}
let m = n.len()... | true |
134d79f3059cc8fda9706ba4154a79fba04014db | Rust | b-ramsey/cargo-generate | /src/git.rs | UTF-8 | 886 | 2.5625 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use git2::{
build::CheckoutBuilder, build::RepoBuilder, Repository as GitRepository, RepositoryInitOptions,
};
use quicli::prelude::*;
use remove_dir_all::remove_dir_all;
use std::path::PathBuf;
use Args;
pub fn create(project_dir: &PathBuf, args: Args) -> Result<GitRepository> {
let mut rb = RepoBuilder::new(... | true |
d63faa075580a490542c4c763c335b56e8df9877 | Rust | racer-rust/racer | /src/racer/codecleaner.rs | UTF-8 | 14,591 | 3.5 | 4 | [
"MIT"
] | permissive | use crate::core::{BytePos, ByteRange};
/// Type of the string
#[derive(Clone, Copy, Debug)]
enum StrStyle {
/// normal string starts with "
Cooked,
/// Raw(n) => raw string started with n #s
Raw(usize),
}
#[derive(Clone, Copy)]
enum State {
Code,
Comment,
CommentBlock,
String(StrStyle)... | true |
3f25a94579101de7158a4a0e2f469e40937aa5cd | Rust | Aloso/parkour | /src/error.rs | UTF-8 | 9,015 | 3.71875 | 4 | [
"MIT",
"Apache-2.0"
] | permissive | use std::fmt;
use std::num::{ParseFloatError, ParseIntError};
use crate::help::PossibleValues;
use crate::util::Flag;
/// The error type when parsing command-line arguments. You can create an
/// `Error` by creating an `ErrorInner` and converting it with `.into()`.
///
/// This error type supports an error source for... | true |
3abb46cea2b60c54f13e04b08078c306026a654a | Rust | philipcraig/mylang | /src/frame.rs | UTF-8 | 8,295 | 3.5625 | 4 | [
"MIT"
] | permissive | use crate::ast::{BinaryOp, Expression, Function, OpName, Statement, UnaryOp};
use std::{collections::HashMap, fmt, rc::Rc};
use thiserror::Error;
#[derive(Debug, PartialEq)]
pub enum Value {
Boolean(bool),
Float(f64),
Function(Rc<Function>),
Integer(i32),
String(Rc<String>),
}
impl fmt::Display fo... | true |
9f6d6cab3295d329c4a4e91d8b2012c420e076ed | Rust | tatetian/ngo2 | /src/libos/src/entry/context_switch/gp_regs.rs | UTF-8 | 1,147 | 2.5625 | 3 | [
"BSD-3-Clause"
] | permissive | use crate::prelude::*;
/// The general-purpose registers of CPU.
///
/// Note. The Rust definition of this struct must be kept in sync with assembly code.
#[derive(Clone, Copy, Debug, Default)]
#[repr(C)]
pub struct GpRegs {
pub r8: u64,
pub r9: u64,
pub r10: u64,
pub r11: u64,
pub r12: u64,
pu... | true |
d9272fe0ee2e4eb06d3f65f8aa5b66cd7332d701 | Rust | Cazadorro/sfal | /src/erfc.rs | UTF-8 | 4,869 | 3.234375 | 3 | [
"MIT"
] | permissive | /// Functions that approximate the erfc(x), the "Complementary Error Function".
use super::erf;
use super::consts;
use std::f64;
///https://en.wikipedia.org/wiki/Error_function#Asymptotic_expansion
pub fn divergent_series(x: f64, max_n: u64) -> f64 {
let mut prod = 1.0;
let mut sum = 1.0;
for n in 1..max_... | true |
e95967df9ce5dd18e8ee73c489ce9ef120d27977 | Rust | fuerstenau/gorrosion-gtp | /src/data/color.rs | UTF-8 | 778 | 2.859375 | 3 | [] | no_license | use super::super::messages::WriteGTP;
use super::*;
use std::io;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Value {
Black,
White,
}
impl WriteGTP for Value {
fn write_gtp(&self, f: &mut impl io::Write) -> io::Result<()> {
match self {
Value::Black => write!(f, "Black"),
Value::White => write!(f,... | true |
f75ec2b2f15bd84d20f2a363894ec906bd7cecb0 | Rust | skanev/playground | /advent-of-code/2021/day09/src/main.rs | UTF-8 | 1,989 | 3.328125 | 3 | [] | no_license | use std::{collections::VecDeque, fs};
fn parse_input() -> Vec<Vec<u8>> {
let text = fs::read_to_string("../inputs/09").unwrap();
let height = text.lines().count();
let width = text.lines().next().unwrap().len();
let mut result = vec![vec![9; width + 2]; height + 2];
for (i, line) in text.lines().... | true |
9170d885608392e23cee3e89a0170fb7bf621d19 | Rust | ArthurMatthys/Gomoku | /src/model/score_board.rs | UTF-8 | 2,434 | 2.875 | 3 | [] | no_license | use super::super::render::board::SIZE_BOARD;
#[derive(Clone, Copy)]
pub struct ScoreBoard([[[(u8, Option<bool>, Option<bool>); 4]; SIZE_BOARD]; SIZE_BOARD]);
impl ScoreBoard {
/// Retrieve score_board[x][y][dir]
pub fn get(&self, x: usize, y: usize, dir: usize) -> (u8, Option<bool>, Option<bool>) {
se... | true |
78e668f8d152738b18f2c4770faed77a5edf2d21 | Rust | kerinin/email-rs | /src/rfc2822/quoted.rs | UTF-8 | 6,883 | 2.734375 | 3 | [] | no_license | use bytes::{Bytes, ByteStr};
use chomp::*;
use rfc2822::folding::*;
use rfc2822::obsolete::*;
use rfc2822::primitive::*;
// quoted-pair = ("\" text) / obs-qp
// Consumes & returns matches
pub fn quoted_pair(i: Input<u8>) -> U8Result<u8> {
parse!{i;
or(
|i| parse!{i; token(b'\\') >> text() },
... | true |
50a892d11aded402f16b56046793a5e33e989d75 | Rust | iCodeIN/rust-advent | /y2020/ex04/src/validators.rs | UTF-8 | 2,842 | 3.34375 | 3 | [
"MIT"
] | permissive | use regex::Regex;
use std::ops::RangeInclusive;
pub trait Validator {
fn validate(&self, value: &str) -> bool;
}
pub struct U16RangeValidator {
range: RangeInclusive<u16>,
}
impl U16RangeValidator {
pub fn new(range: RangeInclusive<u16>) -> Self {
U16RangeValidator { range }
}
}
impl Validat... | true |
158bc4f31dcdf8670799376e3b8855835b601485 | Rust | open-telemetry/opentelemetry-rust | /opentelemetry-sdk/src/testing/trace/in_memory_exporter.rs | UTF-8 | 4,403 | 2.734375 | 3 | [
"Apache-2.0"
] | permissive | use crate::export::trace::{ExportResult, SpanData, SpanExporter};
use futures_util::future::BoxFuture;
use opentelemetry::trace::{TraceError, TraceResult};
use std::sync::{Arc, Mutex};
/// An in-memory span exporter that stores span data in memory.
///
/// This exporter is useful for testing and debugging purposes. It... | true |
2006d078ad47d36d15c36ed32964ca4e48ba983a | Rust | Jackywathy/mipsy | /crates/mipsy_web/src/components/pagebackground.rs | UTF-8 | 800 | 2.640625 | 3 | [] | no_license | use yew::prelude::*;
use yew::{Children, Properties};
#[derive(Properties, Clone)]
pub struct Props {
#[prop_or_default]
pub children: Children,
}
pub struct PageBackground {
pub props: Props,
}
impl Component for PageBackground {
type Message = ();
type Properties = Props;
fn create(props: ... | true |
6f26f1b91aa0aa6fbc61955934f49b2b711a4f1e | Rust | cjoh88/Zombie | /src/editor/input.rs | UTF-8 | 2,246 | 2.921875 | 3 | [] | no_license | use sfml::window::{Key};
use sfml::window::{event};
use sfml::window::MouseButton;
use sfml::graphics::{RenderWindow};
use sfml::system::{Vector2i, Vector2f};
use sfml::graphics::RenderTarget;
use editor::world::World;
pub struct EditorInputHandler {
dummy: i32
}
impl EditorInputHandler {
pub fn new(... | true |
9cfe05532aedfe26141eba73dd1bd0d2ee01e656 | Rust | rust-lang/rust-analyzer | /crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs | UTF-8 | 1,607 | 2.796875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
// Diagnostic: unresolved-macro-call
//
// This diagnostic is triggered if rust-analyzer is unable to resolve the path
// to a macro in a macro invocation.
pub(crate) fn unresolved_macro_call(
ctx: &DiagnosticsContext<'_>,
d: &hir::UnresolvedMacroCal... | true |
2d3c47f93338cb47dfcdef8c16ab9c8fa0fea7bf | Rust | zmbush/cargo | /src/cargo/core/resolver/mod.rs | UTF-8 | 22,960 | 2.546875 | 3 | [
"GCC-exception-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"OpenSSL",
"Zlib",
"MIT",
"curl",
"GPL-2.0-only",
"LicenseRef-scancode-openssl",
"LicenseRef-scancode-ssleay-windows",
"Unlicense",
"LGPL-2.1-only",
"Apache-2.0"
] | permissive | use std::cell::RefCell;
use std::collections::HashSet;
use std::collections::hash_map::HashMap;
use std::fmt;
use std::rc::Rc;
use semver;
use core::{PackageId, Registry, SourceId, Summary, Dependency};
use core::PackageIdSpec;
use util::{CargoResult, Graph, human, ChainError, CargoError};
use util::profile;
use util:... | true |
1b4b1f4dd67bdc635d7c5d9cf5b1e7eb4b3d0c49 | Rust | superhawk610/too-many-lists | /src/first_improved.rs | UTF-8 | 1,590 | 3.984375 | 4 | [] | no_license | /// some easy improvements over `first`
///
/// 1) change `Link` to simply alias `Option<Box<Node>>`
/// 2) substitute `std::mem::replace(x, None)` with `x.take()` (yay, options!)
/// 3) substitute `match option { None => None, Some(x) => Some(y) }` with `option.map(|x| y)`
pub struct List {
head: Link,
}
struct ... | true |
c5dcb378d3f65c5222879e2c91b862b6baf218aa | Rust | steveklabnik/clog | /src/main.rs | UTF-8 | 2,413 | 2.59375 | 3 | [
"MIT"
] | permissive | #![crate_name = "clog"]
#![comment = "A conventional changelog generator"]
#![license = "MIT"]
#![feature(macro_rules, phase)]
extern crate regex;
#[phase(plugin)]
extern crate regex_macros;
extern crate serialize;
#[phase(plugin)] extern crate docopt_macros;
extern crate docopt;
extern crate time;
use git::{ LogRead... | true |
62aae4363ffd1c7035a96dc556dd050825538727 | Rust | geoffjay/codility-rs | /src/binary-gap/lib.rs | UTF-8 | 1,401 | 3.375 | 3 | [] | no_license | #![feature(test)]
extern crate test;
pub fn solution(n: i32) -> i32 {
let mut gap = 0;
let mut largest = 0;
let mut num = n;
let mut init = false;
loop {
// increase gap size when number is zero, and count has been initialized
if num & 1 == 0 {
if init {
... | true |
7ead7a9fcd57b7a557255d3c2f5a347291de7637 | Rust | rust-embedded/embedded-hal | /embedded-hal-nb/src/serial.rs | UTF-8 | 3,970 | 3.421875 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Serial interface.
/// Serial error.
pub trait Error: core::fmt::Debug {
/// Convert error to a generic serial error kind
///
/// By using this method, serial errors freely defined by HAL implementations
/// can be converted to a set of generic serial errors upon which generic
/// code can act.
... | true |
963697e7187c6fc18e4ed1c62c6b6aff79afb9cb | Rust | MiyamonY/atcoder | /abc/036/d/01/src/main.rs | UTF-8 | 2,655 | 2.859375 | 3 | [] | no_license | #[allow(unused_macros)]
macro_rules! scan {
() => {
{
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().to_string()
}
};
(;;) => {
{
let mut line: String = String::new();
std::... | true |
c476bad1aefaa05cf003fa16b01a4248b0e75bc9 | Rust | liu-hz18/rCore-v2 | /src/process/kernel_stack.rs | UTF-8 | 3,748 | 3.5 | 4 | [] | no_license | //! 内核栈 [`KernelStack`]
//!
//! 用户态的线程出现中断时,因为用户栈无法保证可用性,中断处理流程必须在内核栈上进行。
//! 所以我们创建一个公用的内核栈,即当发生中断时,会将 Context 写到内核栈顶。
//!
//! ### 线程 [`Context`] 的存放
//! > 1. 线程初始化时,一个 `Context` 放置在内核栈顶,`sp` 指向 `Context` 的位置
//! > (即 栈顶 - `size_of::<Context>()`)
//! > 2. 切换到线程,执行 `__restore` 时,将 `Context` 的数据恢复到寄存器中后,
//! ... | true |
c35f2531daf6327618f829e4d7e15ea4dc61309f | Rust | gdoct/rustvm | /src/instructions/asl.rs | UTF-8 | 2,522 | 3.140625 | 3 | [
"BSD-3-Clause"
] | permissive | use crate::traits::{ Instruction, VirtualCpu };
use crate::types::{ Byte };
use crate::instructions::generic::*;
fn asl(cpu: &mut dyn VirtualCpu, num: Byte, with: Byte) {
let asl = num << with;
cpu.set_a(asl);
}
/// AslZp: ASL zeropage
/// Arithmetic Shift Left (ASL) operation between
/// the content of Accu... | true |
f7d335dc73bf00f15287442fb8a40d2d3abe1ccc | Rust | jamestthompson3/subtxt-rs | /src/lib.rs | UTF-8 | 2,535 | 3.75 | 4 | [] | no_license | pub struct Parser<'a> {
input: std::str::Lines<'a>,
}
impl<'a> Parser<'a> {
pub fn new(text: &'a str) -> Self {
Self {
input: text.lines(),
}
}
}
impl<'a> Iterator for Parser<'a> {
type Item = Event<'a>;
fn next(&mut self) -> Option<Self::Item> {
match self.inpu... | true |
31e738f9fca604d1584626d02ea022781ef862b6 | Rust | SymmetricChaos/project_euler_rust | /src/worked_problems/euler_76.rs | UTF-8 | 2,993 | 3.5625 | 4 | [] | no_license | // Problem: How many different ways can one hundred be written as a sum of at least two positive integers?
/*
*/
struct AllIntegers {
ctr: i64,
parity: u8,
}
impl Iterator for AllIntegers {
type Item = i64;
fn next(&mut self) -> Option<i64> {
if self.parity == 0 {
self.parity = 1... | true |
6d6eb9ccc92b1b7c0c047bbda5e8f96466302ad9 | Rust | mandx/harplay | /src/har/mod.rs | UTF-8 | 1,559 | 2.9375 | 3 | [
"MIT"
] | permissive | pub mod errors;
pub mod generic;
use std::fs::File;
use std::io::{BufReader, Read};
use std::path::Path;
use serde::{Deserialize, Serialize};
pub use errors::HarError;
use errors::*;
pub use generic::*;
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct Har {
pub log: Log,
}
/// Deserialize ... | true |
4f1f7675a2b1b60a4e4a2ee34b4bc0918db7bf77 | Rust | arielb1/rustc-perf-collector | /src/execute.rs | UTF-8 | 3,855 | 2.609375 | 3 | [
"MIT"
] | permissive | //! Execute benchmarks in a sysroot.
use std::str;
use std::path::{Path, PathBuf};
use std::process::Command;
use tempdir::TempDir;
use rustc_perf_collector::{Patch, Run};
use errors::{Result, ResultExt};
use rust_sysroot::sysroot::Sysroot;
use time_passes::{PassAverager, process_output};
pub struct Benchmark {
... | true |
9dbba9ca63b7899339ef99ae88d923535b42df89 | Rust | matthew86707/PDESimulator | /PDESimulator/src/simulation.rs | UTF-8 | 3,612 | 2.890625 | 3 | [] | no_license | use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
use std::{thread, time};
pub fn simulation_loop(display_values_mutex : Arc<Mutex<[f32; 15000]>>, GRID_SIZE_X : usize, GRID_SIZE_Y : usize){
let TIME_SAMPLES_PER_PRINTOUT : u32 = 100;
let mut time_samples : u32 = 0;
let mut time_ac... | true |
1f4d83c360620fae73a2f35780e132c22c51605e | Rust | kroeckx/ruma | /crates/ruma-events/src/room/redaction.rs | UTF-8 | 2,461 | 2.796875 | 3 | [
"MIT"
] | permissive | //! Types for the *m.room.redaction* event.
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events_macros::{Event, EventContent};
use ruma_identifiers::{EventId, RoomId, UserId};
use serde::{Deserialize, Serialize};
use crate::Unsigned;
/// Redaction event.
#[derive(Clone, Debug, Event)]
#[allow(clippy::exhaus... | true |
072a8fb46341d51bd070b776ebd1071a560ab6dc | Rust | KrutNA/huffman-coding | /src/queue.rs | UTF-8 | 462 | 2.640625 | 3 | [] | no_license | use crate::types::node::*;
use std::collections::BinaryHeap;
pub fn update_with_data(heap_buffer: &mut [u32], data: &[u8]) {
for &byte in data.iter() {
heap_buffer[byte as usize] += 1;
}
}
pub fn convert_to_heap(
heap_buffer: &mut [u32]
)
-> BinaryHeap<Element>
{
heap_buffer.iter().enumerate().f... | true |
2706201ef1c85ac4eb4e84369f6783e76f71263d | Rust | KadoBOT/exercism-rust | /diamond/src/lib.rs | UTF-8 | 705 | 3.203125 | 3 | [] | no_license | pub fn get_diamond(c: char) -> Vec<String> {
let distance = ((c as u8) - b'A') as usize;
let mut result = vec![" ".repeat(distance + distance + 1); distance + distance + 1];
let size = result.len();
let mut replace_char = |idx: usize, pos: usize, ch: char| {
result[idx].replace_range(pos..=pos,... | true |
a988a03a0c59f16e3b29b0bf32f34af8acf6ac10 | Rust | andrew-johnson-4/rdxl_internals | /src/xtext_crumb.rs | UTF-8 | 2,887 | 2.5625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive |
// Copyright 2020, The rdxl Project Developers.
// Dual Licensed under the MIT license and the Apache 2.0 license,
// see the LICENSE file or <http://opensource.org/licenses/MIT>
// also see LICENSE2 file or <https://www.apache.org/licenses/LICENSE-2.0>
use quote::{quote_spanned, ToTokens};
use proc_macro2::{Span, Li... | true |
35e07ed8d1c382e5e625ba0beb0438033033b0fe | Rust | doytsujin/yew | /packages/yew/src/functional/hooks/use_transitive_state/feat_ssr.rs | UTF-8 | 2,278 | 2.6875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //! The server-side rendering variant.
use std::cell::RefCell;
use std::rc::Rc;
use base64ct::{Base64, Encoding};
use serde::de::DeserializeOwned;
use serde::Serialize;
use crate::functional::{Hook, HookContext, PreparedState};
use crate::suspense::SuspensionResult;
pub(super) struct TransitiveStateBase<T, D, F>
wh... | true |
802004b243938e1da6cda1e4bfff6b4a6aab2d05 | Rust | dollarkillerx/Learn-RUST-again | /day2_4/src/main.rs | UTF-8 | 695 | 3.453125 | 3 | [
"MIT"
] | permissive | fn main() {
hello1();
hello2();
}
struct User;
trait Hel {
fn hello(&self) -> String;
}
trait Hum {
fn hello(&self);
fn hello_world<T: Hel>(&self, you: T);
}
struct DK;
impl Hel for DK {
fn hello(&self) -> String {
"hello DK".to_string()
}
}
impl Hum for User {
fn hello(&self) ... | true |
1bc54ef27643c5b481231dd66aa5edd12898efb6 | Rust | ScarboroughCoral/Notes | /剑指Offer/面试题56 - I. 数组中数字出现的次数.rs | UTF-8 | 421 | 3.265625 | 3 | [] | no_license | impl Solution {
pub fn single_numbers(nums: Vec<i32>) -> Vec<i32> {
let mut r=0;
for x in &nums{
r^=x;
}
let mut d=1;
while (d&r)==0{
d<<=1;
}
let mut a=0;
let mut b=0;
for x in &nums{
if x&d==0{
a^=x;
... | true |
e81986963f4f3f3a4fd322b1288ef3f58d4e9e99 | Rust | ens-ds23/ensembl-client | /src/assets/browser/app/src/controller/output/report.rs | UTF-8 | 7,288 | 2.703125 | 3 | [] | no_license | use std::collections::HashMap;
use std::sync::{ Arc, Mutex };
use controller::global::{ App, AppRunner };
use controller::output::OutputAction;
use serde_json::Map as JSONMap;
use serde_json::Value as JSONValue;
use serde_json::Number as JSONNumber;
#[derive(Clone)]
#[allow(unused)]
pub enum StatusJigsawType {
N... | true |
7cbe3f3c5c78b20de4c23dc0199e9d3f80a2c69e | Rust | pormeu/openbrush-contracts | /examples/reentrancy-guard/flip_on_me/lib.rs | UTF-8 | 708 | 2.65625 | 3 | [
"MIT"
] | permissive | #![cfg_attr(not(feature = "std"), no_std)]
#[ink_lang::contract]
pub mod flip_on_me {
use ink_env::call::FromAccountId;
use my_flipper_guard::my_flipper_guard::MyFlipper;
#[ink(storage)]
#[derive(Default)]
pub struct FlipOnMe {}
impl FlipOnMe {
#[ink(constructor)]
pub fn new()... | true |
7fd1fbd2faf430e8d8dfed2219562371e2ef46d0 | Rust | RaymondK99/advent_of_code_2020_rs | /src/util/day_02.rs | UTF-8 | 2,057 | 3.421875 | 3 | [] | no_license | use super::Part;
pub fn solve(input : String, part: Part) -> String {
let list = input.lines()
.map(|line| parse_line(line))
.collect();
let result = match part {
Part::Part1 => part1(list),
Part::Part2 => part2(list)
};
format!("{}",result)
}
fn parse_line(input:&st... | true |
974f376bbe0dfc6d2fe87d7bde6b2462456dd29a | Rust | YoshikawaMasashi/toid | /src/high_layer_trial/phrase_operation/split_by_condition.rs | UTF-8 | 680 | 2.71875 | 3 | [] | no_license | use super::super::super::data::music_info::{Note, Phrase};
pub fn split_by_condition<N: Note + Eq + Ord + Clone>(
phrase: Phrase<N>,
condition: Vec<bool>,
) -> (Phrase<N>, Phrase<N>) {
let mut true_phrase = Phrase::new();
let mut false_phrase = Phrase::new();
true_phrase = true_phrase.set_length(ph... | true |
e221920e5dca5c1739194e031e0a40581847066d | Rust | RevelationOfTuring/Rust-exercise | /src/error_handling_result_early_returns.rs | UTF-8 | 1,265 | 4.09375 | 4 | [
"Apache-2.0"
] | permissive | /*
我们可以显式地使用组合算子处理了错误。
另一种处理错误的方式是使用 `match 语句` 和 `提前返回`(early return)的结合。
也就是说:
如果发生错误,我们可以`停止`函数的执行然后返回错误。
这样的代码更好写,更易读。
*/
#[cfg(test)]
mod tests {
use std::num::ParseIntError;
// 如果遇到
fn multiply(first_num_str: &str, second_num_str: &str) -> Result<i32, ParseIntError> {
let... | true |
a6f6c1b0a2a2212631a11f9881158a39ee17b1a3 | Rust | villor/rustia | /crates/proxy/src/game.rs | UTF-8 | 1,857 | 2.859375 | 3 | [] | no_license | use bytes::BytesMut;
use protocol::{FrameType, packet::ClientPacket};
use crate::{Origin, ProxyConnection, ProxyEventHandler};
/// Event handler that will detect a game protocol handshake and enable XTEA with the correct key
#[derive(Default)]
pub struct GameHandshaker;
impl GameHandshaker {
pub fn new() -> Self... | true |
7f5f0a9ae08b396e66daa292f60f500d7d3265cb | Rust | FreskyZ/fff-lang | /src/vm/builtin_impl.rs | UTF-8 | 48,766 | 2.671875 | 3 | [
"Apache-2.0"
] | permissive |
// Builtin methods implementation
use std::str::FromStr;
use std::fmt;
use lexical::SeperatorKind;
use codegen::FnName;
use codegen::ItemID;
use codegen::Type;
use codegen::Operand;
use codegen::TypeCollection;
use super::runtime::Runtime;
use super::runtime::RuntimeValue;
// Based on the assumpt... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.