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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
b9b187c709d219077d0ce0556d95345d851b72b5 | Rust | thor314/euler-rs-py | /e11-20/src/main.rs | UTF-8 | 14,248 | 3.265625 | 3 | [] | no_license | // main struggle problems in this section were 11 and 18, and to some extent, 12 and 14. 17 was annoying to debug, but not hard.
extern crate timings_proc_macro;
use timings_proc_macro::timings;
#[timings]
fn e11() {
let s: Vec<usize> = std::fs::read_to_string("src/e11.txt")
.unwrap()
.split_whites... | true |
a4dbf32b883b4bd07234c44d6ca7b1b9f9ac6acc | Rust | tocklime/timer | /src/routine.rs | UTF-8 | 3,476 | 3.109375 | 3 | [] | no_license | use crate::workout::FlatStatus;
use serde::Deserialize;
use std::borrow::Cow;
use std::collections::HashMap;
#[derive(Clone, Deserialize, Debug)]
struct SimpleWork {
duration: u32,
name: String,
}
#[derive(Clone, Deserialize, Debug)]
enum Work {
Simple(SimpleWork),
Ref(String),
}
#[derive(Deserialize... | true |
2dbf28f5500ab047f89a2231534b73807690e7d1 | Rust | WJackKing/prokaryote | /src/dna/codon.rs | UTF-8 | 2,492 | 2.671875 | 3 | [] | no_license | use Dna;
use io::BASE_TO_AA;
use protein::aa::Aa;
pub struct Codon {
h: usize,
m: usize,
l: usize,
}
impl Codon {
pub fn from_num<'a>(h: usize, m: usize, l: usize) -> Result<Codon, &'a str> {
if h <= 3 && m <= 3 && l <= 3 {
Ok(Codon { h, m, l })
} else {
Err("nu... | true |
458bab16bf693bf48d1c0d0d80e0ef4590dadf81 | Rust | iCodeIN/freecell | /src/card.rs | UTF-8 | 800 | 3.296875 | 3 | [] | no_license | pub const CARD_HEIGHT: i32 = 96;
pub const CARD_WIDTH: i32 = 71;
#[derive(PartialEq, Eq, Hash, Clone)]
pub struct Card {
pub suit: u8,
pub value: u8,
}
impl Card {
pub fn is_ace(&self) -> bool {
self.value == 0
}
pub fn is_red(&self) -> bool {
self.suit % 2 == 0
}
pub fn fo... | true |
dbb0f08881dc8900f82de2a380aeb0a5ae147d4a | Rust | youknowone/artichoke | /artichoke-backend/src/exception_handler.rs | UTF-8 | 4,729 | 2.8125 | 3 | [
"MIT",
"BSD-2-Clause"
] | permissive | use artichoke_core::value::Value as _;
use std::ffi::c_void;
use crate::exception::{CaughtException, Exception};
use crate::gc::MrbGarbageCollection;
use crate::sys;
use crate::value::Value;
use crate::Artichoke;
/// Extract the last exception thrown on the interpreter.
pub trait ExceptionHandler {
/// Extract th... | true |
cd8c18b8b3118f7cb9ab008c58242dd79cba8bf7 | Rust | esovm/esolangs-guricerin | /hq9plus-rs/src/interpreter.rs | UTF-8 | 2,495 | 3.5 | 4 | [
"MIT"
] | permissive | use std::error::Error;
use std::io::{self, BufWriter, Write};
use std::result::Result;
use crate::token::{self, Token};
#[derive(Debug)]
pub struct Interpreter<W: io::Write> {
writer: BufWriter<W>,
src_code: String,
count: u64,
}
impl<W: io::Write> Interpreter<W> {
pub fn new(output: W, code: String)... | true |
bd5768c41222e7c3f259101fae27d729aceb1ec4 | Rust | JennToo/j2gbc | /j2gbc/src/mmu.rs | UTF-8 | 8,457 | 2.53125 | 3 | [] | no_license | use std::collections::HashSet;
use log::{error, info};
use crate::alu::hi_lo;
use crate::audio::{Audio, AudioSink};
use crate::cart::Cart;
use crate::error::ExecutionError;
use crate::input::Input;
use crate::lcd::Lcd;
use crate::mem::*;
use crate::mmu_exceptions::MmuExceptions;
use crate::timer::Timer;
pub struct M... | true |
950d438b151b398defa30ef654984cbc9bb01623 | Rust | doraneko94/Rust | /qsort/src/main.rs | UTF-8 | 538 | 3.5625 | 4 | [] | no_license | fn partition<T: Ord>(slice: &[T]) -> usize {
let length = slice.len();
if length % 2 == 0 {
return length / 2;
} else {
return (length + 1) / 2;
}
}
fn quicksort<T: Ord>(slice: &mut [T]) {
if slice.len() <= 1 {
return;
}
let pivot_index = partition(slice);
quic... | true |
11108b1a31a148ef7ca9a09cbd2c41d450790fa7 | Rust | iCodeIN/rust-algorithm | /src/sort/quick_sort.rs | UTF-8 | 6,695 | 3.703125 | 4 | [
"MIT"
] | permissive | use sort::{shuffle, SortingOrder};
use utils::partition;
fn quick_sort_impl<T, F>(arr: &mut [T], cmp: F)
where
F: FnMut(&T, &T) -> bool + Copy
{
if arr.len() >=2 {
let pivot_idx = partition(arr, cmp);
quick_sort_impl(&mut arr[..pivot_idx], cmp);
quick_sort_impl(&mut arr[pivot_id... | true |
ba9cff7b612b8b0a1f299e6830970a8ff14e3ff0 | Rust | multiphase-rs/cargo-generate-simulation-multiphysics_rs | /src/test_1.rs | UTF-8 | 11,751 | 2.546875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | const USAGE: &str = "
Usage: test_1 [--dt N] [--plots]
test_1 --help
A template for DEM spherical particles modelling.
This benchmark is taken from
author: XXXX
paper: XXXX
link: XXXX
Description:
-----------
Describe the test in a few lines.
Method:
--------
What specific DEM model is used to model the... | true |
ce9c24fcdacabd6b09fc7e1253ff3fff3613a8a7 | Rust | Shizcow/emoji-rs | /generate/src/lookup_by_name.rs | UTF-8 | 1,160 | 2.53125 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use crate::group_subgroup::Group;
use std::process::Command;
use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
use proc_macro2::TokenStream;
use quote::quote;
use crate::lookup_types::NameLookupEntry;
pub fn dump(groups: &Vec<Group>) {
let mut lookup_by_name: Vec<NameLookupEntry> = vec![];
... | true |
68ba1b3bc500e07f002251508d88c7fddc27aca0 | Rust | alexkingnz/chronoutil | /src/relative_duration.rs | UTF-8 | 9,718 | 3.578125 | 4 | [
"MIT"
] | permissive | //! Implements a RelativeDuration extending Chrono's Duration to shift by months and years.
use core::ops::{Add, Div, Mul, Neg, Sub};
use std::time::Duration as StdDuration;
use chrono::{Date, DateTime, Duration, NaiveDate, NaiveDateTime, TimeZone};
use super::delta::shift_months;
/// Relative time duration extendin... | true |
e10d1e193d2c4e3b81a69282b2bb05f1341723dd | Rust | wyyerd/vectortile-rs | /examples/streets.rs | UTF-8 | 1,462 | 2.875 | 3 | [
"MIT"
] | permissive | extern crate postgres;
extern crate vectortile;
use postgres::{Connection, TlsMode};
use vectortile::{Encode, Tile, Layer, Feature, Value};
use vectortile::grid::Grid;
use std::fs::File;
fn main() {
// WebMercator coordinates for downtown Denver, CO
let zoom = 12;
let x = 853;
let y = 1554;
// Op... | true |
b0a95261e3eecca98c52a751f2f3da091401dc8f | Rust | petabi/eventio | /src/pcap.rs | UTF-8 | 5,948 | 2.734375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | //! Reading packets as events from a pcap input.
use crate::{BareEvent, Error};
use std::io::{self, Read};
use pcap_parser::{
create_reader, data::get_packetdata_ethernet, data::PacketData, traits::PcapReaderIterator,
Block, PcapBlockOwned, PcapError,
};
/// A packet as a byte sequence;
pub type Event = Bare... | true |
6690be99b46149e95f252ce4508522f36d05a4dd | Rust | 18616378431/myCode | /rust/test6-44/src/main.rs | UTF-8 | 482 | 3.40625 | 3 | [] | no_license | //将闭包做为trait对象
//trait限定,静态分发
//trait对象,动态分发,有运行时消耗
trait Any {
fn any(&self, f : &(Fn(u32) -> bool)) -> bool;
}
impl Any for Vec<u32> {
fn any(&self, f: &(Fn(u32) -> bool)) -> bool {
for &x in self.iter() {
if f(x) {
return true;
}
}
false
}
... | true |
0d3461e4e78967c18d7c59b1b71f8c206e206da4 | Rust | ghuls/arrow2 | /src/io/csv/write/mod.rs | UTF-8 | 6,139 | 2.953125 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | mod serialize;
use std::io::Write;
// re-export necessary public APIs from csv
pub use csv::{ByteRecord, Writer, WriterBuilder};
pub use serialize::*;
use crate::record_batch::RecordBatch;
use crate::{datatypes::Schema, error::Result};
/// Creates serializers that iterate over each column of `batch` and serialize ... | true |
91ac404731b31974533c660c2a570f3215c1d50c | Rust | arielhenryson/cheetah | /cheetah_lib/src/parser/expressions/member_expression.rs | UTF-8 | 578 | 2.953125 | 3 | [] | permissive | use super::super::parser::{ Parser, ParseResult } ;
use crate::types::expression::{ Expression, ExpressionDef };
use crate::types::tokens::Token;
impl Parser {
pub fn member_expression(&mut self, object: Expression) -> ParseResult {
self.pos += 1;
let value = self.parse()?;
self.expect(se... | true |
34359166b065c8b8415973c44275233c279c47b3 | Rust | wangchao0502/rust-leetcode | /src/p75_sort_colors.rs | UTF-8 | 1,133 | 3.21875 | 3 | [] | no_license | #![allow(dead_code)]
pub struct Solution {}
// two pointer
impl Solution {
pub fn p75_sort_colors(nums: &mut Vec<i32>) {
// all usize type
let (mut p0, mut p1, mut p2) = (0, 0, nums.len() - 1);
while p1 <= p2 {
match nums[p1] {
0 => {
nums.s... | true |
785e0ccc8625040b8f2893178ea4ab9ca778e52a | Rust | gnoliyil/fuchsia | /src/sys/pkg/bin/omaha-client/src/app_set.rs | UTF-8 | 4,270 | 2.609375 | 3 | [
"BSD-2-Clause"
] | permissive | // Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use {
channel_config::ChannelConfigs,
omaha_client::{app_set::AppSet, common::App},
};
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum AppId... | true |
d89c8d75582723b43f9e1687d1f669040bb03b45 | Rust | ykwmz/leetcode-rust | /src/find_error_nums.rs | UTF-8 | 1,141 | 3.484375 | 3 | [
"MIT"
] | permissive | use std::cmp::max;
// 集合 s 包含从 1 到 n 的整数。不幸的是,因为数据错误,导致集合里面某一个数字复制了成了集合里面的另外一个数字的值,导致集合 丢失了一个数字 并且 有一个数字重复 。
// 2 <= nums.length <= 104
// 1 <= nums[i] <= 104
pub fn find_error_nums(nums: Vec<i32>) -> Vec<i32> {
let mut nums_ordered = vec![0;10001];
let mut max_num = 0;
for num in nums.iter() {
*nu... | true |
0e68963b1763421c7e052c22af130b660888945f | Rust | ia7ck/competitive-programming | /AtCoder/ARC058/B/b.rs | UTF-8 | 3,625 | 3.03125 | 3 | [] | no_license | extern crate proconio;
use proconio::input;
mod mint {
use std::ops::{Add, Div, Mul, Sub};
type Int = i64;
pub const MOD: Int = 1_000_000_000 + 7;
#[derive(Clone, Copy)]
pub struct Mint {
x: Int,
}
impl Mint {
pub fn new(x: Int) -> Mint {
Mint {
... | true |
14e4f49d494046df21f329d53a14cd5c530003df | Rust | jaw-sh/sea-orm | /src/driver/mock.rs | UTF-8 | 5,642 | 2.75 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use crate::{
debug_print, error::*, DatabaseConnection, DbBackend, ExecResult, MockDatabase, QueryResult,
Statement, Transaction,
};
use futures::Stream;
use std::{
fmt::Debug,
pin::Pin,
sync::{
atomic::{AtomicUsize, Ordering},
Arc, Mutex,
},
};
/// Defines a database driver for... | true |
7cdfceb22087359001b70cec2ed591375fb645b0 | Rust | MatchaChoco010/vulkan-ash-tutorial-rust-memo | /techlabxe_vulkan_book_2/src/common/vulkan_objects.rs | UTF-8 | 90,203 | 3.015625 | 3 | [] | no_license | //! Vulkanのオブジェクト用構造体。
//! ハンドルとメモリをまとめるなど。
#![allow(dead_code)]
use std::{ffi::CString, path::Path, rc::Rc};
use anyhow::Result;
use ash::{
extensions::khr::{Surface, Swapchain},
version::DeviceV1_0,
vk, Device, Instance,
};
use image::{DynamicImage, GenericImageView};
/// デバイスローカルなバッファオブジェクト。
/// vk_me... | true |
4203bc7b0d6e7112089162409e5cf288701b0166 | Rust | tauri-apps/tauri | /tooling/bundler/src/bundle/path_utils.rs | UTF-8 | 6,897 | 2.953125 | 3 | [
"Apache-2.0",
"CC0-1.0",
"MIT",
"CC-BY-NC-ND-4.0",
"BSD-3-Clause"
] | permissive | // Copyright 2016-2019 Cargo-Bundle developers <https://github.com/burtonageo/cargo-bundle>
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use std::{
fs::{create_dir, create_dir_all, read_dir, remove_dir_all},
path::{Path... | true |
32e2e81b9e51e75e6a5b730d4f0b9c71db207716 | Rust | MrYankovich/raven-os-org | /src/app/newsletter.rs | UTF-8 | 2,518 | 2.734375 | 3 | [] | no_license | use rocket::http::Status;
use diesel;
use diesel::prelude::*;
use failure::Error;
use uuid::Uuid;
use crate::app::ApiError;
use crate::db::newsletter::models::{NewNewsletterUser, NewsletterUser};
use crate::db::newsletter::schema::newsletter_users;
use crate::db::DbConnection;
#[derive(Clone, Eq, PartialEq, Ord, Pa... | true |
ac4e623827a687751086c9f3ac6e438581c6eb3c | Rust | sammosampson/rust-hotloading-simple | /runner/src/main.rs | UTF-8 | 1,654 | 2.75 | 3 | [] | no_license | mod reloadable_libraries;
use core::time;
use std::thread;
use engine::application_state::*;
use reloadable_libraries::*;
struct Application {
app_library: HotReloadableLibrary,
state: *mut ApplicationState
}
impl Application {
fn new(library_folder: &str) -> Self {
let app_library = HotReloadabl... | true |
dc136719d2327562a43f30ce097ace8deaeacc60 | Rust | gordonhjs/e310x-hal | /src/gpio.rs | UTF-8 | 15,975 | 2.859375 | 3 | [
"ISC"
] | permissive | //! General Purpose I/O
use core::marker::PhantomData;
/// GpioExt trait extends the GPIO0 peripheral.
pub trait GpioExt {
/// The parts to split the GPIO into.
type Parts;
/// Splits the GPIO block into independent pins and registers.
fn split(self) -> Self::Parts;
}
/// Input mode (type state)
pu... | true |
3a261edb2fdb45b614ada96465ee9d36772c3440 | Rust | SchrodingerZhu/password-cli | /src/main.rs | UTF-8 | 3,464 | 2.796875 | 3 | [] | no_license | mod client;
mod utils;
pub use utils::*;
use structopt::*;
use crate::{failed_with, output_res};
use crate::client::{query, Insertion};
use std::io::{stdin, Write};
#[derive(StructOpt, Debug, Eq, PartialEq)]
#[structopt(about = "the password keeper")]
pub(crate) enum Opt {
#[structopt(about = "add a new password")... | true |
c412a9bd44c6a0f586a3ad88392dc9ee359a615b | Rust | jrakow/z3.rs | /z3/src/context.rs | UTF-8 | 7,027 | 2.75 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use z3_sys::*;
use Config;
use Context;
use FuncDecl;
use Sort;
use Symbol;
use {Ast, Params, Pattern};
impl Context {
pub fn new(cfg: &Config) -> Context {
Context {
z3_ctx: unsafe {
let p = Z3_mk_context_rc(cfg.z3_cfg);
debug!("new context {:p}", p);
... | true |
ac86cb79cd8202fa8f43f89ea847894687bdf84c | Rust | yred/euler | /rust/problem_041.rs | UTF-8 | 1,118 | 3.734375 | 4 | [] | no_license | // Problem 41 - Pandigital prime
//
// We shall say that an n-digit number is pandigital if it makes use of all the
// digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is
// also prime.
//
// What is the largest n-digit pandigital prime that exists?
mod common;
use common::primes::Primes;
fn m... | true |
a0848b18d575b112843fad3cfa026a7a966b09ab | Rust | mkindahl/adventofcode2020 | /src/bin/aoc1.rs | UTF-8 | 3,425 | 3.40625 | 3 | [] | no_license | //! Day 1
//!
//! After saving Christmas five years in a row, you've decided to take
//! a vacation at a nice resort on a tropical island. Surely,
//! Christmas will go on without you.
//!
//! The tropical island has its own currency and is entirely
//! cash-only. The gold coins used there have a little picture of a
//... | true |
8a56bba62f1ae88fd89f748226c3ffb89d95c522 | Rust | ivfranco/notes | /Dragon_Book/chapter_3/aho-corasick/src/main.rs | UTF-8 | 1,530 | 3.078125 | 3 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | use aho_corasick::{failure, fibonacci_string, kmp, Trie};
fn main() {
exercise_3_4_3();
exercise_3_4_6();
exercise_3_4_9();
exercise_3_4_11();
}
fn exercise_3_4_3() {
println!("\nExercise 3.4.3:");
let patterns: &[&[u8]] = &[b"abababaab", b"aaaaaa", b"abbaabb"];
for pattern in patterns {... | true |
528ffd6c63100b7ec878feae4191811b8a1553dc | Rust | myuon/ruyt | /src/pdf.rs | UTF-8 | 2,739 | 3.171875 | 3 | [] | no_license | use crate::vector::*;
use crate::figures::*;
pub trait Pdf {
fn value(&self, direction: &V3U) -> f32;
fn generate(&self) -> V3;
}
#[derive(Clone)]
pub struct OnbPdf {
uvw: Onb,
}
impl OnbPdf {
pub fn new(vec: &V3) -> OnbPdf {
OnbPdf {
uvw: Onb::new_from_w(vec),
}
}
}
... | true |
2476e57f5f58194f282b7b5e3ac3913320d80ea3 | Rust | pizzacat83/cprlib | /src/union_find.rs | UTF-8 | 1,148 | 3.375 | 3 | [] | no_license | #[derive(Debug)]
pub struct UnionFind {
parent: Vec<Option<usize>>,
rank: Vec<usize>,
}
impl UnionFind {
pub fn new(size: usize) -> UnionFind {
return UnionFind {
parent: vec![None; size],
rank: vec![0; size],
}
}
pub fn unite(&mut self, x: usize, y: usize) ... | true |
b9093be6e9ed13985808619ca6fe1db9472e80a1 | Rust | sria91-rlox/rox-11 | /src/span.rs | UTF-8 | 3,552 | 2.84375 | 3 | [] | no_license | // Inspiration:
// - [Rust Source](https://github.com/rust-lang/rust/blob/1.45.2/src/librustc_span/lib.rs)
// - [Museun - Neta](https://github.com/museun/neta/blob/04_scanner/src/span.rs)
use std::convert::From;
use std::fmt;
use std::ops::{Add, AddAssign, Index, Sub, SubAssign};
pub trait Pos {
fn from_usize(n: usi... | true |
3f4b204c7859095aaf6911521ce5bb49cc314a30 | Rust | wuggen/gramit | /src/lerp.rs | UTF-8 | 3,561 | 3.21875 | 3 | [
"MIT"
] | permissive | use crate::fp::ApproxEq;
use std::convert::TryFrom;
use std::fmt::{self, Display, Formatter};
use std::ops::{Add, Mul};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/// A value in the range [0, 1].
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize)... | true |
a1f6d6ccdeb5690fbd3444cc52fdb71d8abd484d | Rust | corolanvirus/poll | /src/widgets.rs | UTF-8 | 4,776 | 3 | 3 | [
"MIT"
] | permissive | use std::fmt;
pub trait Dimensions {
fn width(&self) -> i32;
fn height(&self) -> i32;
}
#[derive(Debug)]
pub struct Widget<T> {
width: i32,
height: i32,
padding: i32,
content: T,
}
impl<T: fmt::Display> Widget<T> {
pub fn new(width: i32, height: i32, padding: i32, content: T) -> Self {
... | true |
e3ff9ac5e9445b71228a561773ef39bcebb1bcfd | Rust | Ertibus/TicTacToe | /src/game_logic.rs | UTF-8 | 6,200 | 3.46875 | 3 | [] | no_license | use std::collections::HashMap;
#[derive(Debug, PartialEq)]
enum Player {
X,
O,
}
#[derive(Debug, PartialEq)]
pub enum GameState {
Draw,
Win,
InProgress,
}
const VICTORY_CONDITION: u8 = 2;
pub struct Game {
pub board: HashMap<(u8, u8), char>,
board_size: u8,
player: Player,
}
impl Ga... | true |
1b64fb4d0fcb86db86b6e38f3a5462ac58b6e906 | Rust | bmartynov/stupid_vm | /src/main.rs | UTF-8 | 4,276 | 3.078125 | 3 | [] | no_license | mod assembler;
mod instruction;
use instruction::Instruction;
enum Step {
Halt,
PCNext,
PCSet(usize),
}
struct VM {
pub ir: [i32; 32],
pub pc: usize,
pub sp: usize,
pub bp: usize,
pub running: bool,
pub remainder: i32,
pub compare_flag: bool,
pub loop_counter: usize,
p... | true |
f0f9d7c0d31132afd2dc3277a8c358caf7095884 | Rust | spector-in-london/strobe-rs | /src/strobe.rs | UTF-8 | 19,848 | 2.734375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use crate::{
keccak::{keccakf_u8, AlignedKeccakState, KECCAK_BLOCK_SIZE},
prelude::*,
};
use bitflags::bitflags;
use subtle::{self, ConstantTimeEq};
/// Version of Strobe that this crate implements.
pub const STROBE_VERSION: &str = "1.0.2";
bitflags! {
/// Operation flags defined in the Strobe paper. Thi... | true |
d75059b5f37efa41db8ba2d2c73d024208b4499a | Rust | MEM-Group/Rust-Semantics | /rustsem-java/rust_tests/bindings/t7.rs | UTF-8 | 109 | 2.78125 | 3 | [
"Apache-2.0"
] | permissive |
fn main() {
let mut x = 32;
{
let z = & mut x;
* z = 23;
}
println!("{}", x);
} | true |
d284085395e855b3c95dcdb55af85b9bb82d9279 | Rust | Linksawaking/address_book | /src/main.rs | UTF-8 | 446 | 3.078125 | 3 | [] | no_license | use address_book::AddressBook;
fn main() {
let mut ad = AddressBook::new("Tom");
ad.add_entry("James", "Smith", "+44712345678");
ad.add_entry("James", "Smith", "+44111111111");
println!("{}", ad);
ad.add_entry("James", "Dean", "+44715555655");
ad.add_entry("Bob", "Smith", "+4471321655");
ad... | true |
78bbd3882cecb614f36fa0bf1769a02f44fa54ea | Rust | Happy-Ferret/combustion | /combustion_core/src/graphics/fullscreen.rs | UTF-8 | 1,430 | 2.828125 | 3 | [] | no_license | use glfw::{Glfw, Window, Monitor, WindowMode, VidMode, SwapInterval};
pub struct Toggle {
is_fullscreen: bool,
last_size: (i32, i32),
last_pos: (i32, i32)
}
impl Default for Toggle {
#[inline(always)]
fn default() -> Toggle { Toggle::new() }
}
impl Toggle {
pub fn new() -> Toggle {
To... | true |
8162ef21546ab6f21412f5e71c1493ccdd928f71 | Rust | mvirkkunen/embedded-hal | /src/adc.rs | UTF-8 | 3,425 | 3.734375 | 4 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Analog-digital conversion traits
use nb;
/// A marker trait to identify MCU pins that can be used as inputs to an ADC channel.
///
/// This marker trait denotes an object, i.e. a GPIO pin, that is ready for use as an input to the
/// ADC. As ADCs channels can be supplied by multiple pins, this trait defines the r... | true |
5bc50314b352f813ac2faae269ec9beae3af0c00 | Rust | neosam/ruma-api-macros | /src/metadata.rs | UTF-8 | 2,282 | 3.21875 | 3 | [] | no_license | use quote::{ToTokens, Tokens};
use syn::{Expr, Ident};
#[derive(Debug)]
pub struct Metadata {
pub description: Tokens,
pub method: Tokens,
pub name: Tokens,
pub path: Tokens,
pub rate_limited: Tokens,
pub requires_authentication: Tokens,
}
impl From<Vec<(Ident, Expr)>> for Metadata {
fn fr... | true |
185eaf4d5d89451aa7f690fb51ed4a2c901b836d | Rust | richarddeveloper/AlgebraicManipulatorRust | /src/envs/match_env.rs | UTF-8 | 772 | 2.921875 | 3 | [] | no_license | use env::PushID;
use id::Exp;
#[derive(Debug)]
pub struct MatchEnv<'a> {
data: Vec<(Exp, Exp)>,
parent: Option<&'a MatchEnv<'a>>,
}
impl<'a> MatchEnv<'a> {
pub fn new() -> Self {
MatchEnv { data: vec![], parent: None }
}
pub fn scope<'b>(&'b self, v: Vec<(Exp, Exp)>) -> MatchEnv<'b> where... | true |
fbb7454d2cda9867b0bf7f4fadc3118c32b446c1 | Rust | isgasho/parsercher | /examples/search_tag_from_name.rs | UTF-8 | 340 | 2.8125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use parsercher;
fn main() {
let doc = r#"
<body>
<h1 class="h1">section1</h1>
<h2 class="h2">section2</h2>
<h3 class="h3">section3</h3>
</body>
"#;
if let Ok(dom) = parsercher::parse(&doc) {
if let Some(tags) = parsercher::search_tag_from_name(&dom, "h2") {
println!("{:#?}", tags)... | true |
30bdba8c9e1ea3a97360677016a1da7c1b30691f | Rust | xanahopper/leetcode | /src/leetcode/weekly/weekly_301_4.rs | UTF-8 | 716 | 2.734375 | 3 | [] | no_license | use crate::leetcode::Solution;
#[test]
fn weekly_300_4_test() {
assert_eq!(Solution::ideal_arrays(2, 5), 10);
assert_eq!(Solution::ideal_arrays(5, 3), 11);
}
impl Solution {
pub fn ideal_arrays(n: i32, max_value: i32) -> i32 {
let mut count = vec![vec![0; max_value as usize + 1]; n as usize + 1];
... | true |
4449695d83d51dd802cec45444f465461c3d0208 | Rust | synapticarbors/advent_of_code_2020 | /rust/aoc11/src/main.rs | UTF-8 | 7,973 | 3.015625 | 3 | [] | no_license | use std::io::{self, Read};
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
static MOVE_DIRS: [(isize, isize); 8] = [
(-1, 1),
(0, 1),
(1, 1),
(-1, 0),
(1, 0),
(-1, -1),
(0, -1),
(1, -1),
];
#[derive(Debug)]
enum Part {
P1,
P2,
}
#[derive(Debug, Clone, Cop... | true |
9f574b2222f8b20a56cbbbf03b8c29f215dee95b | Rust | JacobPuff/AoC-2020-Rust | /AoC2020Rust/src/days/day12.rs | UTF-8 | 2,544 | 3.25 | 3 | [] | no_license | use crate::days;
const DIRS: [(i64, i64); 4] = [
(1,0),
(0,1),
(-1,0),
(0,-1),
];
pub fn day12() {
// Part one
day12a();
// Part two
day12b();
}
pub fn day12a() {
let mut current_dir = 0;
let mut x_pos = 0;
let mut y_pos = 0;
let ship_instructions: Vec<String> = d... | true |
1cd83127b03ce91fa12d7c1e19ab0e307f13fbc0 | Rust | Razka173/rust-medium-exercism | /isogram/src/lib.rs | UTF-8 | 612 | 3.15625 | 3 | [] | no_license | use std::collections::HashSet;
pub fn check(candidate: &str) -> bool {
//unimplemented!("Is {} an isogram?", candidate);
if candidate.len() == 0 {
return true;
}
let mut word1 = candidate.to_lowercase();
let mut word2 = candidate.to_lowercase();
word1 = word1.replace(" ", "");
word... | true |
81acea7a84d037210ae87b68dcf9f586b61987ba | Rust | mmillerxyz/hellcheck | /src/notifiers/hipchat.rs | UTF-8 | 1,759 | 2.703125 | 3 | [
"MIT"
] | permissive | use hyper::Uri;
use std::collections::HashMap;
use crate::config::HipchatNotifierConfig;
use crate::notifiers::{Notification, Notifier};
use crate::reactor::State;
pub struct HipchatNotifier {
http_client: ::reqwest::Client,
base_url: Uri,
token: String,
room_id: String,
}
impl HipchatNotifier {
... | true |
f8f97ea21b6897fac28afaa4a714ea67c5ee9a3e | Rust | 0x192/iced_aw | /src/native/overlay/color_picker.rs | UTF-8 | 37,598 | 2.578125 | 3 | [
"MIT"
] | permissive | //! Use a color picker as an input element for picking colors.
//!
//! *This API requires the following crate features to be activated: `color_picker`*
use std::hash::Hash;
use iced_graphics::canvas;
use iced_native::{
button, column, event, keyboard,
layout::{self, Limits},
mouse, overlay, row, text, text... | true |
0687d782f1e0cd2b0714f95646e81893b69c4dbf | Rust | uhyo/tandem-repeat | /src/algorithm/lcp.rs | UTF-8 | 2,170 | 2.59375 | 3 | [
"MIT"
] | permissive | use algorithm::result::AlgoResult;
use algorithm::suffix_array::suffix_array;
use algorithm::lcp_array::{make_inv_sa, lcp_array};
use algorithm::rmq::rmq;
use std::mem;
// LCP Naive algorithm
pub fn algorithm(data_u8: &[u8]) -> AlgoResult {
let len = data_u8.len();
let mut data = Vec::with_capacity(len+1);
... | true |
6b1fd27f16b9ae889848f52cc8b8cda7df3806d8 | Rust | siserin/druid | /examples/layout.rs | UTF-8 | 2,079 | 2.53125 | 3 | [
"Apache-2.0"
] | permissive | // Copyright 2019 The xi-editor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or ag... | true |
f861021b148c344465ed9859bd5e890aba8666f1 | Rust | comradeHsu/lark | /src/instructions/comparisons/ifcond.rs | UTF-8 | 3,515 | 2.9375 | 3 | [
"Apache-2.0"
] | permissive | use crate::instructions::base::branch_logic::branch;
use crate::instructions::base::bytecode_reader::BytecodeReader;
use crate::instructions::base::instruction::{BranchInstruction, Instruction};
use crate::runtime::frame::Frame;
pub struct IfEq(BranchInstruction);
impl IfEq {
#[inline]
pub const fn new() -> I... | true |
fe4405ce0ce03a9a0cc1a54c4f37cd76a96916fc | Rust | bvssvni/ld30 | /ld30/src/rendering.rs | UTF-8 | 2,619 | 2.625 | 3 | [
"MIT"
] | permissive | use gfx;
use device;
use Window;
use piston::vecmath::Matrix4;
use gfx::{Device, DeviceHelper};
use shader_source;
use shader_param::{Program, ShaderParam};
use data;
pub struct Graphics {
device: device::gl::GlDevice,
renderer: gfx::Renderer,
frame: gfx::Frame,
state: gfx::DrawState,
vertices: g... | true |
b094b8621bad92248857bc5b84f7b8be28a44c83 | Rust | nilsmartel/ray-march | /src/main.rs | UTF-8 | 1,240 | 3.25 | 3 | [] | no_license | mod scene;
use scene::*;
fn main() {
println!("Hello, world!");
}
// start by writing the code for the cpu, porting later
struct Ray {
pos: [f32; 2],
z: f32,
color: [f32; 3],
}
#[derive(Copy, Clone)]
struct Global {
thread_x: usize,
max_thread_x: usize,
thread_y: usize,
may_thread_y:... | true |
de7a7657ba4862a8aee895c0de1eea40160e72ab | Rust | dobrite/flexbox-rs | /src/layout.rs | UTF-8 | 5,551 | 2.796875 | 3 | [] | no_license |
use command::Command;
use cursor::Cursor;
use measure;
use offset;
use rect::Rect;
use renderable::Renderable;
use root;
use style;
pub struct Layout<'m> {
measure: &'m measure::Measure,
}
impl<'m, 'r> Layout<'m> {
pub fn new(measure: &'m measure::Measure) -> Self {
Layout { measure: measure }
}
... | true |
98dc00a496fc54d6ce0cf22d22cc235454180c66 | Rust | dsrich/ar-bot | /src/config.rs | UTF-8 | 2,972 | 3.234375 | 3 | [
"MIT"
] | permissive | // config.rs handles loading and eventually writing to the app configuration
use crate::{errors::*, util::file_contents_from_str_path};
use serde_derive::{Deserialize, Serialize};
use std::{fmt, path::PathBuf};
use toml;
static DEFAULT_CONFIG: &'static str = "Bot.toml";
// Eventually, allow for config manipulation vi... | true |
ec470cb2df1bbcc99b09f0a93e0f494fbced77dd | Rust | Srynetix/chip8 | /crates/chip8-gui/src/frames/code.rs | UTF-8 | 2,854 | 3.078125 | 3 | [
"MIT"
] | permissive | //! Code frame.
use std::cmp;
use chip8_core::{
core::types::C8Addr, debugger::DebuggerContext, peripherals::memory::INITIAL_MEMORY_POINTER,
};
use macroquad::prelude::Rect;
use crate::{
draw::{ui_draw_text, ui_draw_text_ex},
frame::Frame,
};
/// Code frame.
pub struct CodeFrame {
frame: Frame,
... | true |
9f3023e2ea87d25d6d5c91e6cfe0ff3ac1922309 | Rust | dalalsunil1986/xv7 | /xv7-bootloader-uefi/src/macros.rs | UTF-8 | 594 | 3.015625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"MIT"
] | permissive | /// Prints and returns the value of a given expression for quick and dirty
/// debugging.
///
/// Copied from standard library with slight modifications.
#[macro_export]
macro_rules! dbg {
() => {
info!("[{}:{}]", file!(), line!());
};
($val:expr) => {
match $val {
tmp => {
... | true |
5b6e5883f0ef4b8ba93430dca71dd0114cc888b8 | Rust | thejohncrafter/projets-2020 | /ir/src/lir/parsing.rs | UTF-8 | 13,255 | 3.03125 | 3 | [
"MIT"
] | permissive |
use automata::lexer::*;
use automata::parser::*;
use automata::line_counter::*;
use automata::read_error::*;
use parsergen::{lex, parse};
use super::types::*;
enum Punct {
LBracket,
RBracket,
LPar,
RPar,
LSquare,
RSquare,
Comma,
Colon,
Semicolon,
Arrow,
Equ,
Neq,
... | true |
0072eaecc647377a4d2a638dc50c9ae986cf544e | Rust | bnied/alamo-movies-rust | /src/alamo_movies/film_title.rs | UTF-8 | 4,328 | 3.125 | 3 | [
"MIT"
] | permissive | use regex::Regex;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parses_bare_title() {
if let Some(film_title) = FilmTitle::parse("FREE SOLO") {
assert_eq!(film_title.show_type, "");
assert_eq!(film_title.title , "FREE SOLO");
assert_eq!(film_title.suffix, ""... | true |
eacddcf4533b3b9689532db03a2994e5ceee5f9a | Rust | xfbs/snake | /src/main.rs | UTF-8 | 3,543 | 3.15625 | 3 | [] | no_license | use rand::Rng;
use std::collections::VecDeque;
use termion::raw::IntoRawMode;
use termion::screen::AlternateScreen;
use termion::event::Key;
use termion::input::TermRead;
use std::io::{Write, stdout, stdin};
#[derive(Clone, Copy, Debug, PartialEq)]
enum Field {
Snake,
Food,
Wall
}
#[derive(Clone, Copy, De... | true |
3610b37e67c83b46a3bf44583a662085aa527c06 | Rust | Gellardo/adventOfCode-2019 | /src/bin/day10.rs | UTF-8 | 1,213 | 3.046875 | 3 | [] | no_license | extern crate env_logger;
#[macro_use]
extern crate log;
use std::fs;
use env_logger::Env;
/// Returns a Vec of (x, y) tuples, one for each astroid/'#'
fn scan_field_for_astroids(scan: Vec<String>) -> Vec<(usize, usize)> {
let mut asteroids = vec![];
for i in 0..scan.len() {
let line_b = scan[i].as_by... | true |
31665ad9534554b59572fdaabf6f1b020461f8bf | Rust | arthurprs/sucredb | /src/hash.rs | UTF-8 | 1,265 | 3.0625 | 3 | [
"MIT"
] | permissive | use crc16;
pub const HASH_SLOTS: u16 = 16384;
/// RedisCluster style partitioning
pub fn hash_slot(mut key: &[u8]) -> u16 {
if let Some(open) = key.iter().position(|&x| x == b'{') {
// note that close will be relative to open due to the skip()
if let Some(close) = key[open + 1..].iter().position(|... | true |
14141dc3aa6e1f2125c626151f01f07fbe091856 | Rust | franc0is/cryptopals | /rust/10/src/main.rs | UTF-8 | 1,888 | 2.90625 | 3 | [] | no_license | #![feature(io)]
extern crate base64;
extern crate itertools;
extern crate openssl;
use itertools::Itertools;
use openssl::symm::*;
use std::env;
use std::fs::File;
use std::io::BufReader;
use std::io::Read;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 3 {
println!("Please provi... | true |
61d02f8dc3324511b651943b8c007cda52279e29 | Rust | dindinw/cita | /consensus/engine/src/instrument.rs | UTF-8 | 307 | 2.734375 | 3 | [] | no_license | use std::time::Duration;
pub fn unix_now() -> Duration {
::std::time::UNIX_EPOCH.elapsed().unwrap()
}
pub trait AsMillis {
fn as_millis(&self) -> u64;
}
impl AsMillis for Duration {
fn as_millis(&self) -> u64 {
self.as_secs() * 1_000 + (self.subsec_nanos() / 1_000_000) as u64
}
} | true |
1e45724dc10712189ab645b9ae9696a1420c5da6 | Rust | likr/atcoder | /abc185/src/bin/b.rs | UTF-8 | 1,001 | 2.609375 | 3 | [] | no_license | use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;
#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;
#[... | true |
e15205e14c30aaae7368a428dad690e0e415b48f | Rust | Spunge/octothorpe | /src/loopable.rs | UTF-8 | 9,312 | 3.1875 | 3 | [] | no_license |
use super::TickRange;
use super::events::*;
use super::TimebaseHandler;
pub trait Loopable {
type Event: LoopableEvent;
fn length(&self) -> u32;
fn events(&self) -> &Vec<Self::Event>;
fn events_mut(&mut self) -> &mut Vec<Self::Event>;
fn clear_events(&mut self) {
self.events_mut().clear(... | true |
fbcd2642fcc55f6280558b951f08b5316d2f9d80 | Rust | mvniekerk/mci-rs | /mci/src/registers/sdio/cccr/function_select.rs | UTF-8 | 1,539 | 3.140625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use crate::registers::register_address::RegisterAddress;
use bit_field::BitField;
use core::hint::unreachable_unchecked;
pub enum FunctionSelection {
FunctionCia0 = 0,
Function1 = 1,
Function2 = 2,
Function3 = 3,
Function4 = 4,
Function5 = 5,
Function6 = 6,
Function7 = 7,
MemoryInCa... | true |
f89fc3a61cce726ef84d2e7b22483e38f774d096 | Rust | sparkle-os/sparkle | /src/arch/x86_64/bits.rs | UTF-8 | 547 | 2.53125 | 3 | [
"BSD-3-Clause"
] | permissive | //! Shorthand for flipping CPU bits.
// TODO: stuff in here should be unsafe; NXE/WRPROT could compromise memory safety.
/// Turn on no-execute page protection.
pub fn enable_nxe() {
use x86_64::registers::model_specific::{Efer, EferFlags};
unsafe {
Efer::update(|flags| *flags |= EferFlags::NO_EXECUT... | true |
82c59253765f8474a5479fb20696271c2f4f46be | Rust | tdejager/mun | /crates/mun_codegen/src/code_gen/linker.rs | UTF-8 | 3,745 | 2.5625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use mun_target::spec;
use mun_target::spec::LinkerFlavor;
use std::ffi::OsString;
use std::path::Path;
use std::path::PathBuf;
use std::process;
use std::process::Command;
pub fn create_with_target(target: &spec::Target) -> Box<dyn Linker> {
match target.linker_flavor {
LinkerFlavor::Ld => Box::new(LdLinke... | true |
f790a4104a9ae2270cc11434da65d677591948b4 | Rust | Hexilee/BronzeDB | /bronzedb-protocol/src/request.rs | UTF-8 | 12,796 | 2.921875 | 3 | [
"MIT"
] | permissive | use crate::ext::{ReadKVExt, WriteKVExt};
use crate::{MAX_KEY, MIN_KEY};
use bronzedb_util::types::{Key, Value};
use byteorder::{ReadBytesExt, WriteBytesExt};
use std::io::{self, Read, Write};
use std::ops::Deref;
use std::u8::MAX;
#[derive(Debug, Copy, Clone)]
pub enum Action {
NoResponse = 0,
Ping = 1,
Se... | true |
9f6ec95845302dde998b551b23163d230f5e7e18 | Rust | r2gnl/xaynet | /rust/xaynet-core/src/mask/object/serialization/mod.rs | UTF-8 | 6,059 | 3.109375 | 3 | [
"Apache-2.0"
] | permissive | //! Serialization of masked objects.
//!
//! See the [mask module] documentation since this is a private module anyways.
//!
//! [mask module]: crate::mask
pub(crate) mod unit;
pub(crate) mod vect;
use anyhow::Context;
use crate::{
mask::object::{
serialization::{unit::MaskUnitBuffer, vect::MaskVectBuffe... | true |
1043a58ee48101c92ea68c44877ee9fed8c18df4 | Rust | gp-97/minigrep-rs | /src/search.rs | UTF-8 | 421 | 2.640625 | 3 | [
"MIT"
] | permissive | use crate::config::Config;
pub fn search_query(config: &Config, content: &String) {
let query: &String = config.get_query();
let mut instances = 0;
for (count, line) in content.lines().enumerate() {
if line.contains(query.as_str()) {
println!("Line {}: {}", count + 1, line);
... | true |
cf4427f30d0ecdfc01f9ea9abe25ba7b2c59b254 | Rust | iic3585-2019/wasm-hamiltonian-cycle-g4 | /crate/src/lib.rs | UTF-8 | 3,781 | 3.046875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use wasm_bindgen::prelude::*;
mod hamiltonian;
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
// Called by our JS entry point to run the example.
#[wasm_bindgen]
pu... | true |
eb3ad23ca36fc2a6b8e2e491d7e43385ef90de0f | Rust | gregokent/tms570 | /src/dcan4/if3upd78/mod.rs | UTF-8 | 53,227 | 2.703125 | 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::IF3UPD78 {
#[doc = r" Modifies the contents of the register"]
#[inline]
pub fn modify<F>(&self, f: F)
where
for<'w> F: FnOnce(&R, &'w ... | true |
6106e1a73017a29e198faae2cb6e7334d27a5ef2 | Rust | ZcashFoundation/zebra | /zebra-consensus/src/router.rs | UTF-8 | 17,071 | 2.78125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"MIT"
] | permissive | //! Top-level semantic block verification for Zebra.
//!
//! Verifies blocks using the [`CheckpointVerifier`] or full [`SemanticBlockVerifier`],
//! depending on the config and block height.
//!
//! # Correctness
//!
//! Block and transaction verification requests should be wrapped in a timeout, because:
//! - checkpoi... | true |
e29c1acb97e74e9339af751164dd63eba312562c | Rust | mihyaeru21/monkey | /src/object/environment.rs | UTF-8 | 970 | 3.28125 | 3 | [] | no_license | use super::*;
use std::collections::HashMap;
#[derive(Debug)]
pub struct Environment {
store: HashMap<String, Rc<Object>>,
outer: Option<Rc<RefCell<Environment>>>,
}
impl Environment {
pub fn new() -> Environment {
Environment {
store: HashMap::new(),
outer: None,
}... | true |
8e5b9025f755aca66af7b8bc83ef25150f835489 | Rust | leftiness/hex_math | /src/traits/range/range.rs | UTF-8 | 1,315 | 3.515625 | 4 | [
"MIT"
] | permissive | use std::borrow::Borrow;
use std::collections::HashSet;
use enums::Direction;
use structs::Point;
use traits::travel::Travel;
use traits::range::Base;
/// Trait wrapping range implementation
pub trait Range: Borrow<Point> {
/// Find the points within the provided manhattan distance
fn range(&self, range: i32) -> ... | true |
0869afae6c62d37a55d5ff4f1fdd53977847d625 | Rust | doraneko94/Rust | /ABS/abc087b/src/main.rs | UTF-8 | 561 | 3.078125 | 3 | [] | no_license | fn read1<T: std::str::FromStr>() -> T {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
s.trim().parse().ok().unwrap()
}
fn main() {
let a = read1::<u32>();
let b = read1::<u32>();
let c = read1::<u32>();
let x = read1::<u32>();
let mut ans = 0;
for a_num in 0.... | true |
cead4c214ab35c6ed2e409adab2d734c36eb8097 | Rust | ryanpbrewster/advent-of-code-2017 | /src/day3.rs | UTF-8 | 3,353 | 3.734375 | 4 | [
"Apache-2.0"
] | permissive | /*
Each square on the grid is allocated in a spiral pattern starting at a location
marked 1 and then counting up while spiraling outward. For example, the first
few squares are allocated like this:
17 16 15 14 13
18 5 4 3 12
19 6 1 2 11
20 7 8 9 10
21 22 23 --> ..
While this is very space-... | true |
1820a1b96923264a5c11735f7a25dcc0d0296be4 | Rust | Just4Ease/aeropi-rs | /src/led.rs | UTF-8 | 518 | 2.796875 | 3 | [] | no_license | use sysfs_gpio::Pin;
lazy_static! {
pub static ref STATUS_LED: LED = LED::new("status_led");
}
pub struct LED {
pin: Pin,
}
impl LED {
pub fn new(name: &str) -> Self {
let pin =
Pin::from_path(format!("/var/run/gpio/{}", name)).expect("Unable to connect to LED");
LED { pin }
... | true |
eba609402f29f8ebd6c3ca3d06a57ebe2bae8948 | Rust | lqd/polonius.next | /src/fact_emitter/test/cfg_edge.rs | UTF-8 | 1,246 | 2.8125 | 3 | [
"MIT"
] | permissive | use super::*;
use insta::assert_debug_snapshot;
#[test]
fn no_edges() {
// Empty block
assert!(expect_facts("bb0: {}").cfg_edge.is_empty());
// Single statement
let program = "
let x: i32;
bb0: {
x = 1;
}
";
assert!(expect_facts(program).cfg_edge.is_empty())... | true |
986808bd142593f225f206583d5530be180096db | Rust | skaban76bitcoinwallet/libra | /language/tools/test_generation/src/transitions.rs | UTF-8 | 13,859 | 2.875 | 3 | [
"Apache-2.0"
] | permissive | // Copyright (c) The Libra Core Contributors
// SPDX-License-Identifier: Apache-2.0
use crate::{
abstract_state::{AbstractState, AbstractValue, BorrowState},
common::VMError,
};
use vm::{
access::*,
file_format::{Kind, SignatureToken, StructDefinitionIndex},
views::{SignatureTokenView, StructDefini... | true |
a6781ac818b13f598f8c4be1765d8a8b54e59894 | Rust | SnowballSH/snake_bf | /src/optimizer.rs | UTF-8 | 327 | 2.546875 | 3 | [] | no_license | pub fn optimize(mut code: String) -> String {
while code.contains("><") || code.contains("<>") ||
code.contains("+-") || code.contains("-+") {
code = code.replace("><", "");
code = code.replace("<>", "");
code = code.replace("+-", "");
code = code.replace("-+", "");
}
... | true |
bd10556b5bc437a71b0c66d2ec1e80c86bad13fb | Rust | jiangzh1206/rust_learning | /src/sort/bubble.rs | UTF-8 | 417 | 3.203125 | 3 | [] | no_license | #![allow(dead_code)]
// 坏O(n²), 好O(n)
pub fn bubble_sort(arr: &mut [i32]) {
//0..i =>[0,i)
for i in (0..arr.len()).rev() {
let mut flag = true;
for j in 0..i {
if arr[j] > arr[j + 1] {
arr.swap(j, j + 1);
flag = false;
}
}
... | true |
672ecdde4300be8dad194e608fe12440fbd1a3f9 | Rust | Xudong-Huang/may | /src/local.rs | UTF-8 | 4,389 | 3.1875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use std::any::TypeId;
use std::cell::RefCell;
use std::collections::HashMap;
use std::hash::{BuildHasherDefault, Hasher};
use std::ptr::NonNull;
use std::sync::Arc;
use crate::coroutine_impl::Coroutine;
use crate::join::Join;
use generator::get_local_data;
// thread local map storage
thread_local! {static LOCALMAP: L... | true |
a533a5691cc89e09759ebe1bb596d9dbf4bcb11d | Rust | Ostrzy/SpaceEmpire | /src/main.rs | UTF-8 | 10,659 | 2.875 | 3 | [] | no_license | #![feature(core)]
extern crate sdl2;
use std::rc::Rc;
use std::hash::{Hash, Hasher, Writer};
use std::cell::RefCell;
use std::collections::HashMap;
use std::collections::HashSet;
use std::ops::Add;
use std::num::ToPrimitive;
use self::sdl2::render::RenderDrawer;
use self::sdl2::rect::{Rect, Point};
use self::sdl2::pi... | true |
57b3a4b55468af39cfbb57757b21ee8b77a0e8ae | Rust | WF-Engineering/sendinblue | /src/mailer.rs | UTF-8 | 324 | 2.859375 | 3 | [
"MIT"
] | permissive | use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct Mailer {
pub name: String,
pub email: String,
}
impl Mailer {
pub fn new<S>(name: S, email: S) -> Self
where
S: Into<String>,
{
Self {
name: name.into(),
email: email.into(),
}
... | true |
aaae239be70c1621eb108b534a70829a97e70ba7 | Rust | AnumEssani/Assignment3 | /q1/src/main.rs | UTF-8 | 460 | 3.453125 | 3 | [] | no_license | fn main() {
fn consume_with_relish<F:FnOnce()->String>(func: F)
where F: FnOnce() -> String
{
println!("Consumed: {}", func());
println!("Super Happy I did it!");
}
// fn once function always consume values whether it is in println form or in its variabl... | true |
d6eb3ec5514e79f29e9790de9bae19586fb42332 | Rust | aatxe/oxide-test-suite | /nll/issue-52534-1-6.rs | UTF-8 | 148 | 2.84375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | fn foobaz<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 {
let z = 22;
&z
//~^ ERROR cannot return reference to local variable
}
fn main() { }
| true |
78ec424fc5ab0958de18fc95cd3962d6304d584a | Rust | fenhl/srcomapi-rs | /src/util.rs | UTF-8 | 1,763 | 3.109375 | 3 | [
"MIT"
] | permissive | use {
std::time::Duration,
bigdecimal::{
BigDecimal,
ToPrimitive,
Zero
},
lazy_static::lazy_static,
regex::Regex,
serde::Deserialize
};
lazy_static! {
static ref DURATION_RE: Regex = Regex::new("^PT(?:([0-9.]+)H)?(?:([0-9.]+)M)?(?:([0-9.]+)S)?$").unwrap();
}
#[deriv... | true |
e14bf04a00e6c6c231374b03c6e321ab817c9f18 | Rust | thoov/volta | /crates/validate-npm-package-name/src/lib.rs | UTF-8 | 10,034 | 2.953125 | 3 | [
"BSD-2-Clause-Views",
"BSD-2-Clause"
] | permissive | //! A Rust implementation of the validation rules from the core JS package
//! [`validate-npm-package-name`](https://github.com/npm/validate-npm-package-name/).
use lazy_static::lazy_static;
use percent_encoding::{utf8_percent_encode, AsciiSet, NON_ALPHANUMERIC};
use regex::Regex;
/// The set of characters to encode,... | true |
3538efbd39fc9a430cb6b7e21481cd268fc020ef | Rust | ebml-rs/ebml-rs | /src/decoder.rs | UTF-8 | 14,616 | 2.515625 | 3 | [] | no_license | use crate::ebml;
use crate::schema::{Schema, SchemaDict};
use crate::vint::{read_vint, UnrepresentableLengthError};
use chrono::{DateTime, NaiveDateTime, Utc};
use err_derive::Error;
use log_derive::{logfn, logfn_inputs};
use std::convert::TryFrom;
pub trait ReadEbmlExt: std::io::Read {
#[logfn(ok = "TRACE", err =... | true |
e4e3dd7d1c06f2cba64b9a43ba0cd1f9f4731719 | Rust | povilasb/rust-playground | /generic_number_stdin.rs | UTF-8 | 578 | 3.265625 | 3 | [] | no_license | use std::io;
use std::str::FromStr;
use std::fmt::Debug;
fn main() {
let nums = read_numbers::<u64>();
for n in nums {
println!("{}", n);
}
}
fn read_numbers<T>() -> Vec<T>
where
T: FromStr,
T::Err: Debug
{
match readln() {
Ok(ln) => {
ln.split_whitespace()
... | true |
7abc9b7efd0934d4c809f47d00f8a136f443c3cf | Rust | Gopiandcode/rust-projects | /genetic_algorithm_cipher/src/ngram/mod.rs | UTF-8 | 2,185 | 3.359375 | 3 | [] | no_license | use ::std::collections::HashMap;
use ::std::fmt::{
Display,
Formatter,
};
use ::std::fmt;
pub struct NgramFrequency {
frequency: HashMap<String,f64>,
slice_size: usize,
total: u32,
floor: f64
}
impl NgramFrequency {
pub fn generate_from(text : &String, slice_size: usize) -> NgramFrequen... | true |
9b34278f4f780488a912b0b436e202e51ef31c33 | Rust | erickgnavar/exercism | /rust/assembly-line/src/lib.rs | UTF-8 | 456 | 2.90625 | 3 | [] | no_license | // This stub file contains items that aren't used yet; feel free to remove this module attribute
// to enable stricter warnings.
#![allow(unused)]
pub fn production_rate_per_hour(speed: u8) -> f64 {
let rate = match speed {
1..=4 => 100.0,
5..=8 => 90.0,
_ => 77.0,
};
(rate / 100.0... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.