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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
6956e646a70aebd2d4815c6026f9e78de025ed6e | Rust | i-am-ok-dont-worry/mage2rustimporter | /src/adapters/attributes.rs | UTF-8 | 1,408 | 2.640625 | 3 | [] | no_license | use crate::magentoclient::MagentoRestClient;
use crate::elasticsearch::ESClient;
use crate::adapters::ImportAdapter;
use crate::entities::product::ProductMapper;
use std::time::{Duration, Instant};
use log::{info};
use crate::entities::category::CategoryMapper;
use crate::entities::attribute::AttributeMapper;
pub stru... | true |
a41bdae23a6b1145ea627611e636e97bc8de06c8 | Rust | jswrenn/typelayout | /src/fromzeros.rs | UTF-8 | 2,445 | 3.109375 | 3 | [] | no_license | use crate::*;
use core::mem;
use frunk::hlist::{HCons, HNil};
use frunk_core::generic::Generic;
/// ## Working Example
/// This marker trait is implemented for structs iff it is `ReprC`, has no
/// padding bytes, and all fields are also `FromZeros`:
/// ```rust
/// use typelayout::{ReprC, Generic, Layout, FromZeros};
... | true |
b55f5ddcfc20f63086b419ef38c427bee2ff4130 | Rust | IThawk/rust-project | /rust-master/src/test/ui/async-await/unused-lifetime.rs | UTF-8 | 1,035 | 3.0625 | 3 | [
"MIT",
"LicenseRef-scancode-other-permissive",
"Apache-2.0",
"BSD-3-Clause",
"BSD-2-Clause",
"NCSA"
] | permissive | // edition:2018
// Avoid spurious warnings of unused lifetime. The below async functions
// are desugered to have an unused lifetime
// but we don't want to warn about that as there's nothing they can do about it.
#![deny(unused_lifetimes)]
#![allow(dead_code)]
pub async fn october(s: &str) {
println!("{}", s);
... | true |
b19520c27fd752646bfe0e8661ba1b70dfd8fbce | Rust | sirkibsirkib/axial | /src/tests.rs | UTF-8 | 13,535 | 2.921875 | 3 | [] | no_license | use bidir_map::BidirMap;
use std::collections::HashMap;
use std::thread;
use super::Authenticator;
use super::*;
///////////////////////////// TEST IMPLEMENTATION //////////////////////////////
#[derive(Debug)]
struct TestAuthenticator {
users: BidirMap<ClientId, String>,
secretwords: HashMap<ClientId, Strin... | true |
e9f92a4d59800e8d15ed256b31c2183c533c149b | Rust | stanciua/exercism | /rust/atbash-cipher/src/lib.rs | UTF-8 | 1,219 | 3.4375 | 3 | [
"MIT"
] | permissive | use std::collections::HashMap;
use std::ascii::AsciiExt;
pub fn encode(input: &str) -> String {
let encode_cipher = "0123456789abcdefghijklmnopqrstuvwxyz"
.chars()
.zip("0123456789zyxwvutsrqponmlkjihgfedcba".chars())
.collect::<HashMap<_, _>>();
let encoded_text = input.to_lowercase()
... | true |
06c831e09cf6ff454912a44d461540ce1daa71de | Rust | joshuaholmes/rustboy9001 | /src/main.rs | UTF-8 | 1,514 | 2.828125 | 3 | [
"MIT"
] | permissive | // Main driver of the program.
//
// Author: Joshua Holmes
//
use std::str;
use std::env;
mod rom;
mod util;
use rom::Rom;
fn main() {
// get the filename from the command args and load the ROM
let args: Vec<_> = env::args().collect();
let filename = &args[1];
let rom_file: Rom = match Rom::from_f... | true |
69bd9849d9b6f594af5b202559a3d457ea8ca08f | Rust | aleksrutins/litelytics_rs | /src/types.rs | UTF-8 | 1,055 | 2.75 | 3 | [] | no_license | use serde::{Deserialize};
// Data to pass to Client::log_in
pub struct LogInPayload {
pub instance_url: String,
pub email: String,
pub password: String
}
// Result of login API call
#[derive(Deserialize)]
#[allow(non_snake_case)]
#[allow(dead_code)]
pub(crate) struct LogInResult {
pub success: bool,
... | true |
812239a8faa9815f26d5733e8100c52743357767 | Rust | Zekka/relations-rs | /src/experimental/relations/onetoone/interfaces.rs | UTF-8 | 2,988 | 2.6875 | 3 | [] | no_license | use experimental::handle::Handle;
use experimental::relations::source::*;
use experimental::relations::onetoone::implementation::*; // we could make ReiV and ReiM type parameters, but why?
use experimental::table::Table;
use experimental::loops::BreakContinue;
pub(crate) trait Abstract<TFrom, TTo> {
fn reify<'q>(... | true |
86709187a2c20aee682ba5f784a9ef875b49b0ab | Rust | opensourcegeek/rumqttd | /src/client/mod.rs | UTF-8 | 20,096 | 2.734375 | 3 | [
"Unlicense"
] | permissive | use std::fmt::{self, Debug};
use std::net::SocketAddr;
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
use std::collections::VecDeque;
use std::time::{Duration, Instant};
use futures::sync::mpsc::Sender;
use futures::{Future, Sink};
use mqtt3::*;
use error::{Result, Error};
#[derive(Debug, Clone, Copy,... | true |
15681b162c7b6f213fbfc0e37feb24ad39efe15c | Rust | billpmurphy/lambda_extensions | /src/data/convert.rs | UTF-8 | 363 | 2.921875 | 3 | [
"CC0-1.0"
] | permissive | //! Conversion traits
/// Attempted conversion from a `Term` to Rust type.
pub trait TryFromTerm<T> {
/// Performs the conversion
fn try_from(&self) -> Option<T>;
}
/// Attempted conversion from a Church-encoded datatype `Term` to Rust type.
pub trait TryFromTermChurch<T> {
/// Performs the conversion
... | true |
f848ee820db66cd5a8733c8c01d12985ad53dcdc | Rust | drocco007/tr | /src/lex.rs | UTF-8 | 7,190 | 3.3125 | 3 | [] | no_license | use std::mem::replace;
use bstr::{ByteSlice};
#[derive(Debug)]
pub struct Lexer<'a> {
s: &'a str,
tokens: Vec<Token>,
state: State,
}
#[derive(Debug,PartialEq)]
pub enum TokenType {
Literal,
CharRange,
CharRepeat,
CharClass,
Equivalence,
}
#[derive(Debug,PartialEq)]
enum State {
... | true |
5a2d4d1db948264fe7285cf8d2118161b1bb6ade | Rust | safrannn/leetcode_rust | /src/_1486_xor_operation_in_an_array.rs | UTF-8 | 438 | 3.484375 | 3 | [] | no_license | struct Solution;
impl Solution {
pub fn xor_operation(n: i32, start: i32) -> i32 {
let mut result = start;
for i in 1..n {
result ^= start + i * 2;
}
result
}
}
#[test]
fn test() {
assert_eq!(Solution::xor_operation(5, 0), 8);
assert_eq!(Solution::xor_operat... | true |
9f58a92a51045fcb01dc7cbbad633399ac98f7db | Rust | dejankos/AoC2020 | /src/day_3.rs | UTF-8 | 2,053 | 3.296875 | 3 | [] | no_license | type Map = Vec<Vec<char>>;
fn count_trees(map: Map) -> usize {
count_trees_part_2(&map, 3, 1)
}
fn count_all(map: Map) -> usize {
vec![
count_trees_part_2(&map, 1, 1),
count_trees_part_2(&map, 3, 1),
count_trees_part_2(&map, 5, 1),
count_trees_part_2(&map, 7, 1),
count_... | true |
2b14c574834d950a0cd7ac187b58c1b3cd6fc4dc | Rust | pyigyli/JRPG-engine | /src/data/enemies.rs | UTF-8 | 3,209 | 2.671875 | 3 | [] | no_license | use ggez::{Context, GameResult};
use ggez::timer::ticks;
use rand::{Rng, thread_rng};
use crate::battle::action::{ActionParameters, DamageType};
use crate::battle::enemy::{Enemy, Animation};
use crate::party::Party;
use crate::party::item::{InventoryItem, ItemVariant};
use crate::menu::notification::Notification;
fn g... | true |
bb8b6df1c11450ad139fb58f8fdf09306f7c6847 | Rust | marco-c/gecko-dev-wordified-and-comments-removed | /third_party/rust/chrono/src/oldtime.rs | UTF-8 | 20,917 | 2.765625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"MIT"
] | permissive | use
core
:
:
ops
:
:
{
Add
Div
Mul
Neg
Sub
}
;
use
core
:
:
time
:
:
Duration
as
StdDuration
;
use
core
:
:
{
fmt
i64
}
;
#
[
cfg
(
any
(
feature
=
"
std
"
test
)
)
]
use
std
:
:
error
:
:
Error
;
const
NANOS_PER_MICRO
:
i32
=
1000
;
const
NANOS_PER_MILLI
:
i32
=
1000_000
;
const
NANOS_PER_SEC
:
i32
=
1_000_000_000
;
c... | true |
89bccc5ff94355e4717ff795e13c60822e8e839a | Rust | edwardycl/RustPython | /common/src/hash.rs | UTF-8 | 3,688 | 2.90625 | 3 | [
"CC-BY-4.0",
"MIT"
] | permissive | use num_bigint::BigInt;
use num_complex::Complex64;
use num_traits::ToPrimitive;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::num::Wrapping;
pub type PyHash = i64;
pub type PyUHash = u64;
/// Prime multiplier used in string and various other hashes.
pub const MULTIPLIER: PyHa... | true |
61b3503516bb2d2223ff9c4ce445d1a4b14bb1c1 | Rust | tianenchen/leetcode-rs | /src/offer/median_finder.rs | UTF-8 | 2,017 | 3.703125 | 4 | [] | no_license | use std::cmp::Reverse;
struct MedianFinder {
count: usize,
min_heap: std::collections::BinaryHeap<Reverse<i32>>, //小堆存中位数大于
max_heap: std::collections::BinaryHeap<i32>, //大堆存小
}
/**
* `&self` means the method takes an immutable reference.
* If you need a mutable reference, change it to `&mut se... | true |
8d994277435f125f7298c4335e61bc9afecde476 | Rust | 10xabou/rkm | /rkm/src/common.rs | UTF-8 | 1,815 | 3.34375 | 3 | [
"MIT"
] | permissive | use ndarray::{ArrayView1, ArrayView2, Ix, ScalarOperand};
use num::{Float, NumCast, Zero};
use std::cmp::PartialOrd;
use std::fmt::Debug;
use std::marker::Sync;
use std::ops::Add;
/// Numeric value trait, defines the types that can be used for the value of each dimension in a
/// data point.
pub trait Value:
Scala... | true |
ca4b28d88a6c3c5e5c512c2772ceca8fa26676ac | Rust | kroeckx/ruma | /crates/ruma-events-macros/src/event_content.rs | UTF-8 | 12,132 | 2.546875 | 3 | [
"MIT"
] | permissive | //! Implementations of the MessageEventContent and StateEventContent derive macro.
use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote};
use syn::{
parse::{Parse, ParseStream},
DeriveInput, Ident, LitStr, Token,
};
use crate::event_parse::EventKind;
mod kw {
// This `content` field is k... | true |
7d59bc9c3489b610048d06ef70fcbb7fc4ee419c | Rust | SlashScreen/rustrendertake2 | /src/main.rs | UTF-8 | 5,392 | 3.09375 | 3 | [] | no_license | //raytraces an image
//Include
extern crate image;
extern crate piston_window;
extern crate bvh;
use piston_window::EventLoop;
use bvh::ray::Ray;
use bvh::nalgebra::{Point3,Vector3};
//Const
const WIDTH: u32 = 1280;
const HEIGHT: u32 = 720;
//STRUCTS
//Point - a holder for x,y,z.
#[allow(dead_code)]
struct Point
{
... | true |
7e29a9cb5620c0d732abec0b109be02f5444834d | Rust | apache/incubator-teaclave-sgx-sdk | /sgx_tstd/src/io/readbuf.rs | UTF-8 | 12,128 | 3.09375 | 3 | [
"BSD-3-Clause",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | // Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may... | true |
f103e8d022c61ae842e77fe65f8df114332e49fd | Rust | hawnzug/mal | /src/steps/step2_eval.rs | UTF-8 | 1,815 | 2.984375 | 3 | [] | no_license | use types::MalType;
use reader::read_str;
use printer::pr_str;
use std::collections::HashMap;
pub fn read(s: &str) -> MalType {
read_str(s)
}
pub fn print(m: MalType) -> String {
pr_str(&m)
}
pub fn rep(s: &str, env: &mut HashMap<String, MalType>) -> String {
print(eval(read(s), env))
}
pub fn eval(ast:... | true |
b2ed7a170e8da7eeb7bf05d4a3398deb31d6a561 | Rust | paulotten/advent_of_code_2019 | /day15/src/main.rs | UTF-8 | 432 | 2.921875 | 3 | [] | no_license | mod data;
mod intcode;
use intcode::Int;
fn main() {
part1();
}
fn part1() {
let data = data::get_data();
let intcodes = get_intcodes(data);
let mut computer = intcode::Computer::new();
computer.set_intcodes(&intcodes);
while computer.run().is_some() {};
// see part1.xlsx and part2.xlsx... | true |
68c19bfad85e5ae4f22ee5502bdb8ea7339d10fb | Rust | ben-han-cn/vanguard2 | /src/config/mod.rs | UTF-8 | 2,888 | 2.5625 | 3 | [] | no_license | use anyhow;
use serde::{Deserialize, Serialize};
use std::{fs::File, io::prelude::*, path::Path};
const DEFAULT_MESSAGE_CACHE_SIZE: usize = 10240;
#[derive(Default, Debug, Deserialize, Serialize)]
pub struct VanguardConfig {
#[serde(default)]
pub server: ServerConfig,
#[serde(default)]
pub auth: Autho... | true |
c0b58fc0cc5c0123d366dd71a0cfa1d17923a843 | Rust | async-rs/async-std | /src/collections/vec_deque/from_stream.rs | UTF-8 | 583 | 2.515625 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use std::collections::VecDeque;
use std::pin::Pin;
use crate::prelude::*;
use crate::stream::{self, FromStream, IntoStream};
impl<T: Send> FromStream<T> for VecDeque<T> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
stream: S,
) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
... | true |
1fb7b07414c12359a2a31784fd4e27904b8ed2fc | Rust | TakoShochou/aizu | /ITP1/4b.rs | UTF-8 | 238 | 2.65625 | 3 | [] | no_license | fn main () {
let mut l = String::new();
std::io::stdin().read_line(&mut l).ok();
let r = l.trim().parse::<f64>().ok().unwrap();
println!(
"{:.6} {:.6}",
r * r * std::f64::consts::PI,
2. * r * std::f64::consts::PI
)
} | true |
967d896ae851362b7911d4a6cd3b1188db3d7c35 | Rust | msehnout/zram-generator | /src/main.rs | UTF-8 | 5,478 | 2.84375 | 3 | [] | no_license | /* SPDX-License-Identifier: MIT */
#[macro_use]
extern crate failure;
extern crate ini;
use failure::Error;
use ini::Ini;
use std::env;
use std::fmt;
use std::fs;
use std::io::prelude::*;
use std::os::unix::fs::symlink;
use std::path::{Path, PathBuf};
use std::result;
pub trait ResultExt<T, E>: failure::ResultExt<T,... | true |
c99976d331a8d2d64aabd42de105f5c6f1ec739e | Rust | jyn514/docs.rs | /crates/font-awesome-as-a-crate/src/lib.rs | UTF-8 | 2,371 | 3.203125 | 3 | [
"MIT"
] | permissive | /*!
This is the [Font Awesome Free](https://fontawesome.com/how-to-use/on-the-web/setup/hosting-font-awesome-yourself) SVG files as a crate.
This is not officially supported by Fonticons, Inc.
If you have problems, [contact us](https://github.com/rust-lang/docs.rs/issues), not them.
*/
use std::error::Error;
use std:... | true |
10237ae52eef15fe4fce65d30bd83840b724f240 | Rust | Florob/threadlings | /03-shared_memory/sm2.rs | UTF-8 | 779 | 3.0625 | 3 | [] | no_license | // sm2.rs
// Make this compile, without using a Mutex
// Scroll down for hints
use std::sync::Arc;
use std::thread;
const NUM_THREADS: u32 = 4;
const INCREMENTS: u32 = 1_000_000;
fn main() {
let counter = Arc::new(0u32);
let handles: Vec<_> = (0..NUM_THREADS)
.map(|_| {
let thread_counte... | true |
682d91a8739c70f7458d144da9ec9697aefad0c8 | Rust | bartekus/jets | /src/utils/fst/codec.rs | UTF-8 | 2,424 | 2.828125 | 3 | [] | no_license | use crate::utils::FOR;
use crate::utils::{get_v32, put_v32};
use bytes::{Buf, BufMut, Bytes, BytesMut};
use std::error::Error;
use std::result::Result;
pub trait Codec {
type Item;
fn write(&self, bf: &mut BytesMut, value: &Self::Item) -> Result<(), Box<dyn Error>>;
fn read(&self, bf: &mut Bytes) -> Resul... | true |
b6960f34137e28765d4f9a8a069d8d1566c18fdb | Rust | dkeehl/chunfen | /src/tunnel_port.rs | UTF-8 | 6,085 | 2.5625 | 3 | [
"MIT"
] | permissive | // Tunnel Port
use std::io::{self, Write, Read};
use tokio_io::AsyncRead;
use tokio_tcp::TcpStream;
use futures::{Sink, Stream, Future, Poll, Async};
use futures::sync::mpsc::{self, Sender, Receiver};
use bytes::Bytes;
use chunfen_socks::{ShutdownWrite, pipe};
use chunfen_socks::connector::{Connector, Socks... | true |
316f879a0cb897f39a4db8dcbf69b00a338985c7 | Rust | lucianoforks/self-modifying-elf-prototype | /command_web/src/resources/entry/delete.rs | UTF-8 | 691 | 2.625 | 3 | [
"MIT"
] | permissive | use crate::util::*;
use serde::Deserialize;
#[derive(Deserialize)]
pub(crate) struct EntryDelete {
pub(crate) old_name: String,
}
pub(crate) fn entry_delete(
(data, req): (Form<EntryDelete>, HttpRequest<AppState>),
) -> HttpResponse {
let b = core::entry::write(
&req.state().ctx,
&WriteEnt... | true |
6fdf93cd3b0614cd592a104bb3ea57a68948c6f3 | Rust | tcr/rust-hindley-milner | /src/lib.rs | UTF-8 | 22,278 | 3.265625 | 3 | [
"MIT"
] | permissive | #[macro_use] extern crate maplit;
#[macro_use] extern crate lazy_static;
use std::collections::{HashMap, HashSet};
use std::fmt;
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Syntax {
Lambda {
v: String,
body: Box<Syntax>,
},
Identifier {
name: String,
},
Apply {
... | true |
11c27b469079f35a4356ad0166ef1fa3cd117744 | Rust | isgasho/core_detect | /src/lib.rs | UTF-8 | 5,525 | 3.46875 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! This crate provides a `no_std` version of std's [`is_x86_feature_detected!`]
//! macro.
//!
//! This is possible because x86 chips can just use the `cpuid` instruction to
//! detect CPU features, whereas most other architectures require either reading
//! files or querying the OS.
//!
//! # Usage
//!
//! ```
//! # ... | true |
12accaf63cbc057d3c40f86aec4e0a643807a995 | Rust | TGElder/rust | /frontier/src/actors/bridge_builder.rs | UTF-8 | 4,638 | 2.578125 | 3 | [
"CC-BY-4.0"
] | permissive | use crate::avatar::{Rotation, Vehicle};
use crate::bridges::BridgeType::Built;
use crate::bridges::{Bridge, Pier};
use crate::system::{Capture, HandleEngineEvent};
use crate::traits::{AddBridge, RemoveBridge, WithWorld};
use commons::async_trait::async_trait;
use commons::edge::Edge;
use commons::grid::Grid;
use common... | true |
55e536df03e5ebe0200e3d8b51554dcb23824317 | Rust | stijnh/rust-advent-of-code-2019 | /src/main.rs | UTF-8 | 1,561 | 2.671875 | 3 | [] | no_license | #![allow(clippy::many_single_char_names)]
#![allow(clippy::needless_range_loop)]
#[macro_use]
mod common;
mod day01;
mod day02;
mod day03;
mod day04;
mod day05;
mod day06;
mod day07;
mod day08;
mod day09;
mod day10;
mod day11;
mod day12;
mod day13;
mod day14;
mod day15;
mod day16;
mod day17;
mod day18;
mod day19;
mod ... | true |
aa61e69eed983285bd1084df2470845b2f79eb8f | Rust | TimonPost/amethyst-server | /amethyst-server/src/pong.rs | UTF-8 | 2,048 | 2.984375 | 3 | [] | no_license | use amethyst::{
assets::{AssetStorage, Loader},
core::transform::Transform,
ecs::prelude::World,
prelude::*,
};
use {Ball, Paddle, Side};
use {ARENA_HEIGHT, ARENA_WIDTH};
pub struct Pong;
impl<'a, 'b> SimpleState<'a, 'b> for Pong {
fn on_start(&mut self, data: StateData<GameData>) {
let St... | true |
f6241fd45d475532e385a516a02090dc6d3b5ee6 | Rust | smith61/ls_cxx | /src/parent_process.rs | UTF-8 | 3,444 | 2.75 | 3 | [] | no_license |
use futures::{
Async,
Future,
Poll
};
use futures::sync::{
oneshot
};
use std::{
io,
time,
thread
};
use tokio_core::reactor::{
Core,
Handle,
Timeout
};
#[cfg( windows )]
mod os {
use kernel32::{
CloseHandle,
GetExitCodeProcess,
OpenProcess
};
... | true |
942335b6fde49316d68166bae758209d44a0d7b0 | Rust | joeyjoejoejr/nand2tetris | /src/memory_access.rs | UTF-8 | 6,594 | 3.109375 | 3 | [] | no_license | #[derive(Debug)]
pub struct MemoryAccess {
pub command: AccessCommand,
pub segment: Segment,
pub index: i32,
pub original: String,
pub filename: String,
}
impl MemoryAccess {
pub fn to_asm(&self) -> String {
match &self {
// Pop commands
MemoryAccess {
command: AccessCommand::Pop,
... | true |
2cc95cf26820602f650aae920c106b6b8c016d6f | Rust | FedericoPonzi/advent-of-code | /2019/src/days/day_8.rs | UTF-8 | 1,098 | 2.984375 | 3 | [] | no_license | use crate::days::Result;
use itertools::Itertools;
pub fn solve(input: String, layer_size: u64) -> Result<u64> {
let layers: Vec<String> = input
.trim()
.chars()
.chunks(layer_size as usize)
.into_iter()
.map(|chunk| chunk.collect::<String>())
.collect::<Vec<_>>();
... | true |
733a0407b0ceb94ab5075c7cb7f33d565105bd78 | Rust | fujiehuang/leetcode-rust | /264.ugly-number-ii.rs | UTF-8 | 850 | 3.15625 | 3 | [] | no_license | /*
* @lc app=leetcode id=264 lang=rust
*
* [264] Ugly Number II
*/
// @lc code=start
impl Solution {
pub fn nth_ugly_number(n: i32) -> i32 {
if n <= 0 { return -1; }
let mut ugly_numbers = vec![1; n as usize];
let mut i2 = 0;
let mut i3 = 0;
let mut i5 = 0;
... | true |
4b23db66a8264fb9644796c54bcedcb062a67f1f | Rust | parkerziegler/rust-book | /deref_trait/src/main.rs | UTF-8 | 1,922 | 4.25 | 4 | [] | no_license | use std::ops::Deref;
fn main() {
let x = 5;
let y = &x;
assert_eq!(x, 5);
// Since we define y as a reference to x, we must dereference
// it later to compare it to the i32 value 5.
assert_eq!(*y, 5);
// The dereference operator also works on Box. Here, it indicates
// to Rust to foll... | true |
5060b74617b115d506850ff4c2ebe9201945e3b8 | Rust | mahdisml/rbatis | /example/src/transaction_test.rs | UTF-8 | 2,821 | 2.78125 | 3 | [
"Apache-2.0"
] | permissive | #[cfg(test)]
mod test {
use crate::BizActivity;
use rbatis::rbatis::Rbatis;
use rbatis::executor::{Executor, RbatisRef, RBatisTxExecutor, ExecutorMut, RbatisExecutor};
use rbatis::core::db::DBExecResult;
use std::cell::Cell;
use async_std::sync::Mutex;
//示例-Rbatis使用事务
#[tokio::test]
... | true |
29216bb1a22ec85217e21a6b1a248b75fec3a135 | Rust | SaitoTech/saito-core | /core/primitives/src/crypto.rs | UTF-8 | 1,090 | 2.53125 | 3 | [] | no_license | use sha2::Sha256;
use digest::Digest;
pub use merkle::{MerkleTree, Hashable};
pub use ring::digest::{SHA256, Context};
pub use secp256k1::{Secp256k1, Message, Signature, SecretKey, PublicKey};
pub use rand::{Rng, thread_rng};
pub use base58::{ToBase58};
use serde::{Serialize, Deserialize};
#[derive( Serialize, Deseri... | true |
d9cafddc5923d8959a1f9df9934913693d46a534 | Rust | nikomatsakis/rust | /src/test/run-pass/anon-obj-backwarding.rs | UTF-8 | 423 | 2.65625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"LicenseRef-scancode-other-permissive",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"bzip2-1.0.6",
"BSD-1-Clause"
] | permissive | use std;
fn main() {
obj inner() {
fn a() -> int { ret 2; }
fn m() -> uint { ret 3u; }
fn z() -> uint { ret self.m(); }
}
let my_inner = inner();
let my_outer =
obj () {
fn b() -> uint { ret 5u; }
fn n() -> str { ret "world!"; }
wit... | true |
0ddb03110176a24901652a22eadb4d5fcb6921c4 | Rust | nickmachnik/keep-in-touch | /src/subcommands.rs | UTF-8 | 6,750 | 2.59375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use clap::ArgMatches;
use log::{error, info};
use crate::helpers::{get_date, get_interval, get_table_path, update_autocomplete_names};
use crate::table::{Entry, Table};
pub fn just_talked_to(args: ArgMatches) {
let table_path = get_table_path();
let data = Table::from_json(&table_path);
if let Err(e) = da... | true |
ac3a3063b1f8465cee555db10f74ee8d57c4355b | Rust | Ten0/serde-xml-rs | /src/ser/mod.rs | UTF-8 | 15,328 | 3.296875 | 3 | [
"MIT"
] | permissive | use std::fmt::Display;
use std::io::Write;
use serde::ser::{self, Serialize};
use self::var::{Map, Struct};
use self::seq::Seq;
use self::tuples::Tuple;
use error::{Error, Result};
mod var;
mod seq;
mod helpers;
mod tuples;
/// A convenience method for serializing some object to a buffer.
///
/// # Examples
///
///... | true |
1f13c6c4afefdbb3fb8c7a4f3786baabeb6967e0 | Rust | rohan-sircar/actix-demo-postgres | /src/routes/auth.rs | UTF-8 | 2,609 | 2.703125 | 3 | [] | no_license | use actix_web::web;
use actix_web_httpauth::extractors::basic::BasicAuth;
use crate::actions::users;
use crate::{errors, AppConfig};
use actix_identity::Identity;
use actix_web::{get, Error, HttpResponse};
#[get("/login")]
pub async fn login(
id: Identity,
credentials: BasicAuth,
config: web::Data<AppConf... | true |
d0141d1e10a4ca90f18e0eae3900baaba72d81d4 | Rust | sksat/cetkaik_full_state_transition | /src/probabilistic.rs | UTF-8 | 3,807 | 3.546875 | 4 | [] | no_license | /// Describes the probability density due to the sticks cast.
/// /投げ棒に由来する確率分布。
#[derive(Debug, Clone)]
pub enum Probabilistic<T> {
Pure(T),
Water {
failure: T,
success: T,
},
Sticks {
s0: T,
s1: T,
s2: T,
s3: T,
s4: T,
s5: T,
},
W... | true |
017f109d7a026aed7e217c7b0527d85f4b795bbd | Rust | cholcombe973/ceph_safe_disk | /lib/exec.rs | UTF-8 | 1,197 | 2.921875 | 3 | [
"MIT"
] | permissive | use crate::error::CSDError;
use users::get_current_username;
use std::process::Command;
pub fn call_ceph(cmd: &str) -> Result<String, CSDError> {
debug!("calling ceph {} -f json", cmd);
let ceph = Command::new("/usr/bin/env")
.args(&["sh", "-c", &format!("ceph {} -f json", cmd)])
.output()?;
... | true |
780cbdb891c3384572bb3908fc6d825b6aaeb727 | Rust | Posnet/speice.io-md_shootout | /src/marketdata_proto.rs | UTF-8 | 1,419 | 2.578125 | 3 | [] | no_license | #[derive(Clone, PartialEq, ::prost::Message)]
pub struct Trade {
#[prost(uint64, tag="1")]
pub price: u64,
#[prost(uint32, tag="2")]
pub size: u32,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LevelUpdate {
#[prost(uint64, tag="1")]
pub price: u64,
#[prost(uint32, tag="2")]
... | true |
5ed33de93e761386ab9659dc73c53f5cc453545e | Rust | ruieduardolopes/monet | /src/capture/osi/transport/multimedia/structs/fragment.rs | UTF-8 | 438 | 2.6875 | 3 | [] | no_license | use std::net::Ipv4Addr;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Fragment {
pub ssrc: u32,
pub dest_address: Ipv4Addr,
pub stream_port: u16,
pub timestamp: u32,
}
impl Fragment {
pub fn new(ssrc: u32, dest_address: Ipv4Addr, stream_port: u16, timestamp: u32) -> Self {
Fra... | true |
f89057f2a6a6b6e3895a09daf87fcd450f76834e | Rust | bytecodealliance/lucet | /lucet-module/src/globals.rs | UTF-8 | 5,552 | 3.171875 | 3 | [
"LLVM-exception",
"Apache-2.0"
] | permissive | use serde::{Deserialize, Serialize};
/// A WebAssembly global along with its export specification.
///
/// The lifetime parameter exists to support zero-copy deserialization for the `&str` fields at the
/// leaves of the structure. For a variant with owned types at the leaves, see
/// [`OwnedGlobalSpec`](owned/struct.... | true |
f8e36a2d2e9f265a58d8c0500c0c671e89cd3a9c | Rust | openstax/adaptarr-server | /crates/rest-api/src/conversations.rs | UTF-8 | 2,158 | 2.6875 | 3 | [] | no_license | use actix_web::{
HttpRequest,
HttpResponse,
web::{self, Payload, Path, Json, ServiceConfig},
};
use adaptarr_conversations::Client;
use adaptarr_models::{
db::Connection,
models::{
FindModelError,
Model,
conversation::Conversation,
}
};
use adaptarr_web::{Database, Sessio... | true |
dc7acec4de4cd1cd6082158e4bf6da75e68b8183 | Rust | dktrotti/minver_rs | /src/build_utils.rs | UTF-8 | 2,765 | 3.015625 | 3 | [
"MIT"
] | permissive | use anyhow::Result;
use git2::Repository;
use std::env;
use std::ffi::OsString;
use std::fs;
use std::path::Path;
use toml_edit::{value, Document};
use crate::MinverConfig;
/// Environment variable that determines if minver_rs will update the crate version. If this
/// variable is not set, then no action will be take... | true |
fbe8b070818abb93510bfd1620dcbab95377744d | Rust | kieraneglin/diecast | /src/actions/repo/load.rs | UTF-8 | 893 | 3.03125 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"MIT"
] | permissive | use colored::*;
use clap::ArgMatches;
use git2::Repository;
use helpers::directory;
pub fn main(matches: &ArgMatches) {
// Unwrap is fine, since clap verifies these exist
let arguments = matches.subcommand_matches("load-git").unwrap();
let url = arguments.value_of("url").unwrap();
load_repo(url);
}
f... | true |
b69f62c56f08a4dde3e439cbdba3bac57d6ad3a4 | Rust | geolffrey/gsc-client | /src/errors.rs | UTF-8 | 5,208 | 3.109375 | 3 | [
"MIT"
] | permissive | use super::RemotePattern;
use error_chain::*;
use serde_derive::{Serialize, Deserialize};
use std::path::PathBuf;
/// This is the format of error messages produced by the server.
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct JsonStatus {
pub status: u16,
pub title: Stri... | true |
3dc0f5d08b6ad3057ae0dd9ac4231e1641803da0 | Rust | JHowell45/rust-practise | /chapter_6/concise_control_flow/src/main.rs | UTF-8 | 392 | 3.234375 | 3 | [
"MIT"
] | permissive | fn main() {
let some_u8_value = Some(0u8);
match some_u8_value { // version 1
Some(3) => println!("three"),
_ => (),
}
println!("some_u8_value: {:?}", some_u8_value);
if let Some(3) = some_u8_value { // version 2
println!("three");
}
println!("some_u8_value: {:?}", some_u8_value);
// ve... | true |
994cbccfe1791d097993016c9d8c1b3ece49854a | Rust | mesalock-linux/crates-sgx | /vendor/wasmi/src/func.rs | UTF-8 | 12,199 | 2.875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use alloc::{
borrow::Cow,
sync::{Arc, Weak},
vec::Vec,
};
use core::fmt;
use host::Externals;
use isa;
use module::ModuleInstance;
use parity_wasm::elements::Local;
use runner::{check_function_args, Interpreter, InterpreterState, StackRecycler};
use types::ValueType;
use value::RuntimeValue;
use {Signature,... | true |
b8597295ce4506eb645f5e8dfd9953959dffd6f4 | Rust | mtvu/influxdb_iox | /influxdb_iox/src/commands/run/database.rs | UTF-8 | 3,846 | 2.546875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! Implementation of command line option for running server
use std::sync::Arc;
use crate::{
influxdb_ioxd::{
self,
server_type::{
common_state::{CommonServerState, CommonServerStateError},
database::{
setup::{make_application, make_server},
... | true |
4b816d5ef49f21c5a7ff5ec0a85874ff5d3e5691 | Rust | hershi/cryptopals_rust | /ex_14_byte_by_byte_hard/src/main.rs | UTF-8 | 4,726 | 2.984375 | 3 | [] | no_license | #[macro_use]
extern crate lazy_static;
use rand::prelude::*;
use std::collections::HashMap;
use std::io::prelude::*;
use std::io::BufReader;
use std::fs::File;
use data_encoding::BASE64;
use utils::*;
use utils::encoding::*;
use utils::encryption::*;
const BLOCK_SIZE : usize = 16;
const KEY_SIZE : usize = 16;
const A... | true |
bad6f9c16e45d41b2017140af598acb1841145a8 | Rust | idevgames/idevgames.com | /cargo-project/src/github_client.rs | UTF-8 | 5,700 | 3.578125 | 4 | [
"BSD-2-Clause"
] | permissive | //! Super-simple client for interacting with the Github API. This is clearly
//! very incomplete, but it does have the few API calls that iDevGames needs to
//! function.
use reqwest::Client as ReqwestClient;
use serde::Deserialize;
use thiserror::Error;
/// Abstraction for interfacing with Github. This encapsulates ... | true |
42e7d36badaabf6e4671fe6ddb27456450e57f10 | Rust | Undo3D/opinionated-rust-to-typescript | /src/rs2018_ts4/lexemize/detect/identifier.rs | UTF-8 | 4,081 | 4.125 | 4 | [] | no_license | //! Detects an identifier, like `String` or `foo_bar`.
/// Detects an identifier, like `String` or `foo_bar`.
///
/// @TODO raw identifiers, which have the `r#` prefix
///
/// ### Arguments
/// * `orig` The original Rust code, assumed to conform to the 2018 edition
/// * `pos` The character position in `orig` to loo... | true |
022c10ce739267b4312b751d17caddb7998c1b7a | Rust | gwendalF/natrium_backend | /src/domain/auth/auth_types/key_identifier.rs | UTF-8 | 507 | 3.25 | 3 | [] | no_license | use thiserror::Error;
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct Kid(String);
impl Kid {
pub fn new(value: String) -> Result<Kid, KidError> {
Ok(Kid(validate(value)?))
}
pub fn value(&self) -> &str {
&self.0
}
}
fn validate(value: String) -> Result<String, KidError> {
... | true |
c38bd737ad4f38e71fd8f431bd840e6737c8ceee | Rust | mxgrey/test_repeater | /src/main.rs | UTF-8 | 1,322 | 3.078125 | 3 | [] | no_license | use std::process::Command;
use argparse::{ArgumentParser, Store, Collect};
use std::io::{self, Write};
fn main() {
let mut command = String::new();
let mut args = Vec::<String>::new();
let mut cycles = 100u32;
{
let mut parser = ArgumentParser::new();
parser.set_description("Repeat a ... | true |
32f6c7b184b27520e9911556d18bc15fb239ed26 | Rust | HamaguRe/twelite_serial_master | /src/main.rs | UTF-8 | 8,308 | 3.3125 | 3 | [] | no_license | // TWELITEの親機にシリアルでデータを送って無線で子機に転送
//
// TWELITEのファームウェアは公式配布の「シリアル通信アプリ」
// 書式モード・バイナリー形式(AI2ピンLo)
// 115200bps,8bit parity none, ストップビット1
use std::io;
use std::thread;
use std::io::prelude::*;
use std::time::Duration;
use std::fs;
use std::io::{Write, BufWriter, Read, BufRead, BufReader};
use serial;
use serial::pr... | true |
974aacb288f2b256da12151dec822b187c22ce9a | Rust | little-dude/netlink | /genetlink/src/connection.rs | UTF-8 | 1,745 | 2.734375 | 3 | [
"MITNFA",
"MIT"
] | permissive | // SPDX-License-Identifier: MIT
use crate::{message::RawGenlMessage, GenetlinkHandle};
use futures::channel::mpsc::UnboundedReceiver;
use netlink_packet_core::NetlinkMessage;
use netlink_proto::{
self,
sys::{protocols::NETLINK_GENERIC, AsyncSocket, SocketAddr},
Connection,
};
use std::io;
/// Construct a ... | true |
59da2f8d2b664e272ac9f428c836d8150e4a1bbc | Rust | sensorfu/luomu-libpcap | /luomu-libpcap/src/lib.rs | UTF-8 | 18,517 | 2.53125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #![deny(
future_incompatible,
nonstandard_style,
rust_2018_compatibility,
rust_2018_idioms,
unused,
missing_docs
)]
//! # luomu-libpcap
//!
//! Safe and mostly sane Rust bindings for [libpcap](https://www.tcpdump.org/).
//!
//! We are split in two different crates:
//!
//! * `luomu-libpcap-sy... | true |
2a58870b9719a262d0f898afc401799d987a509a | Rust | RNAcentral/rnacentral-import-pipeline | /utils/precompute/src/main.rs | UTF-8 | 6,656 | 2.65625 | 3 | [
"GPL-1.0-or-later",
"Apache-2.0",
"Artistic-1.0-Perl",
"LicenseRef-scancode-other-copyleft",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::path::PathBuf;
use structopt::StructOpt;
pub mod accessions;
pub mod metadata;
pub mod normalize;
pub mod releases;
use crate::metadata::file_types::FileType;
#[derive(Debug, StructOpt)]
#[structopt(rename_all = "kebab-case")]
enum MetadataCommand {
/// Merge each distinct type of metadata into single m... | true |
c983838d42f36d6fb418c2a8081302bb74e03c82 | Rust | tytouf/roulios | /lib/volatile.rs/src/lib.rs | UTF-8 | 2,471 | 2.90625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #![feature(no_std)]
#![no_std]
#![feature(core_intrinsics)]
//! Volatile registers
//!
//! Newtypes to mark a region of memory as a volatile register.
//!
//! NOTE: This crate is meant to be used only with Cortex-M processors (a.k.a. ARM
//! microcontrollers).
//!
//! All operations should (*) be atomic unless otherwi... | true |
d8522e3206466af14cd5a3382afdb0353bbb914d | Rust | Logicalshift/flowbetween | /user_interfaces/gtk_ui/src/canvas/cairo_draw.rs | UTF-8 | 25,767 | 3 | 3 | [
"Apache-2.0"
] | permissive | use super::viewport::*;
use flo_canvas as flo;
use flo_canvas::*;
use cairo;
use cairo::*;
///
/// The current source colour that's set
///
#[derive(Copy, Clone, PartialEq)]
enum ColorTarget {
None,
Stroke,
Fill
}
///
/// A saved state in a Cario drawing surface
///
struct SavedState {
dash_pattern:... | true |
415343b89a6449c8239aed4840da2115d3fa9b13 | Rust | Luminarys/ring-buffer | /src/lib.rs | UTF-8 | 5,229 | 3.25 | 3 | [] | no_license | use std::sync::atomic::{AtomicUsize, Ordering};
use std::cell::UnsafeCell;
use std::mem;
use std::thread;
use std::time::Duration;
/// Lockfree SPSC fixed size ring buffer.
pub struct RingBuffer<T> {
size: usize,
items: UnsafeCell<Vec<Option<T>>>,
write_pos: AtomicUsize,
read_pos: AtomicUsize,
}
unsaf... | true |
462e701635590171db23469c78852e522ed935a8 | Rust | dimforge/ncollide | /src/bounding_volume/aabb_ball.rs | UTF-8 | 986 | 2.90625 | 3 | [
"Apache-2.0"
] | permissive | use crate::bounding_volume::{HasBoundingVolume, AABB};
use crate::math::{Isometry, Point, Vector};
use crate::shape::Ball;
use na::RealField;
/// Computes the Axis-Aligned Bounding Box of a ball transformed by `center`.
#[inline]
pub fn ball_aabb<N: RealField + Copy>(center: &Point<N>, radius: N) -> AABB<N> {
AABB... | true |
0c48eb7add96d2618764a5947639d7f80f7cee5b | Rust | vycb/rusttol | /src/node.rs | UTF-8 | 2,002 | 3.359375 | 3 | [] | no_license | use std::fmt;
use rustc_serialize::json::{ToJson, Json};
use std::collections::HashMap;
#[derive(Clone, Eq, PartialEq, Hash, Debug, RustcDecodable, RustcEncodable)]
pub struct Node {
pub id: String,
pub name: String,
pub parent: Option<Box<Node>>,
pub othername: String,
pub description: String
}
i... | true |
2d8c216b25c3d7e64d7109b384e88634c218e5d8 | Rust | MovingtoMars/liams_4x | /src/common/game_world.rs | UTF-8 | 23,174 | 3.1875 | 3 | [] | no_license | use std::collections::BTreeMap;
use serde::{Serialize, Deserialize};
use crate::common::*;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum ProducingItemId {
// TODO use UnitTemplateId
Unit(UnitTemplate),
Building(BuildingTypeId),
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum Produc... | true |
fcc1348ef0e7e8afaa51b7340aa4a68795171c9b | Rust | ivfranco/notes | /AI/and_or_search/src/vaccum_cleaner.rs | UTF-8 | 4,362 | 2.859375 | 3 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | use petgraph::prelude::*;
use std::{
collections::{HashSet, HashMap},
hash::Hash,
};
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
enum Cleanliness {
Clean,
Dirty,
}
use Cleanliness::*;
impl Cleanliness {
fn label(self) -> u8 {
match self {
Clean => 1,
Dirty => 0,
... | true |
690f456c583d92b411d487766cf26c66a77654f9 | Rust | umairaiot/06 | /src/main.rs | UTF-8 | 934 | 3.859375 | 4 | [] | no_license | #[derive(Debug)]
struct Employee {
first_name: String,
last_name: String,
age: i8,
married: bool,
height: f32,
}
fn main() {
let employee_01 = Employee {
first_name: String::from("abc"),
last_name: "xyz".to_string(),
age: 25,
married: false,
height: 5.6,
};
let employee_02 =... | true |
9c4928e5262cd172fd0b66a2be7ba5f99c26a82f | Rust | perdumonocle/yofix | /src/settings.rs | UTF-8 | 5,580 | 2.796875 | 3 | [] | no_license | #[allow(unused_variables)]
#[allow(dead_code)]
#[derive(Debug, Clone, Default)]
#[allow(non_snake_case)]
pub struct SettingsBuilder {
pub fix_yo: bool,
pub fix_ye: bool,
pub prefer_yo: bool,
pub word_a: Option<String>,
pub word_b: Option<String>,
pub char_yo: Option<String>,
pub char_ye: Op... | true |
0b44c0ea786606e3a4879498fc0785542c5923c1 | Rust | nstoddard/webgl-wrapper | /src/surface.rs | UTF-8 | 3,966 | 3.171875 | 3 | [
"MIT"
] | permissive | use cgmath::*;
use web_sys::*;
use crate::context::*;
use crate::framebuffer::*;
use crate::rect::*;
/// A trait for things that can be rendered to.
pub trait Surface {
/// Binds the `Surface` and sets the appropriate viewport.
#[doc(hidden)]
fn bind(&self, context: &GlContext);
/// Binds the `Surfac... | true |
171cb1b7f0cf1d9e61cc1e36b18b30f6b30b0efa | Rust | sketchc89/rebalancing-tool | /src/asset.rs | UTF-8 | 3,397 | 3.9375 | 4 | [
"MIT"
] | permissive | extern crate separator;
use separator::FixedPlaceSeparatable;
use std::fmt;
#[derive(Clone, PartialEq)]
pub enum AssetClass {
Domestic,
International,
Bond,
//Cd,
RealEstate,
}
pub struct Asset {
pub class: AssetClass,
pub value: f64
}
impl fmt::Display for AssetClass {
fn fmt(&self, f:... | true |
5d7c904e1d67560eda6120d53448f56689326f13 | Rust | ScottDillman/rune | /crates/rune/src/ast/lit_byte.rs | UTF-8 | 3,724 | 2.921875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use crate::ast;
use crate::{
Parse, ParseError, Parser, Resolve, ResolveError, ResolveErrorKind, ResolveOwned, Spanned,
Storage, ToTokens,
};
use runestick::{Source, Span};
/// A byte literal.
#[derive(Debug, Clone, PartialEq, Eq, ToTokens, Spanned)]
pub struct LitByte {
/// The token corresponding to the ... | true |
5101e45e07dd30c23f682b9fe14c31bbc9d6e40f | Rust | cbarrazaa1/rs-math-interpreter | /src/interpreter.rs | UTF-8 | 7,650 | 3.515625 | 4 | [] | no_license | use crate::parser::{ExprNode};
use std::collections::HashMap;
use std::f32::consts::PI;
fn pow(interp: &mut Interpreter, args: &Vec<Box<ExprNode>>) -> Result<f32, &'static str> {
if args.len() != 2 {
return Err("Incorrect arguments for pow function: expected pow(num, exp)")
}
Ok(interp.eval(&*ar... | true |
ceb922e8b043f7c86ca489b991c5588a0dff6add | Rust | raviqqe/pir | /pir/src/ir/primitive.rs | UTF-8 | 313 | 3.3125 | 3 | [
"Apache-2.0"
] | permissive | #[derive(Clone, Copy, Debug, PartialEq)]
pub enum Primitive {
Boolean(bool),
Number(f64),
}
impl From<bool> for Primitive {
fn from(boolean: bool) -> Self {
Self::Boolean(boolean)
}
}
impl From<f64> for Primitive {
fn from(number: f64) -> Self {
Self::Number(number)
}
}
| true |
048649346559ae2b64bf1f393bb01fe4191d6cbf | Rust | jnigri/EPI | /6.7/main.rs | UTF-8 | 524 | 3.296875 | 3 | [] | no_license | use std::cmp;
fn compute_differences(a: &Vec<i32>) -> Vec<i32> {
let mut v = Vec::new();
for i in 0..(a.len() - 1) {
v.push(a[i + 1] - a[i]);
}
v
}
fn main() {
let prices = vec![310, 315, 275, 295, 260, 270, 290, 230, 255, 250];
let differences = compute_differences(&prices);
let m... | true |
881cde376d20597ff872d21d244232c2d0d73b0b | Rust | lo48576/fbxcel | /src/writer/v7400/binary/attributes.rs | UTF-8 | 12,849 | 2.6875 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Node attributes writer.
use std::{
convert::TryFrom,
io::{self, Seek, SeekFrom, Write},
};
use crate::{
low::v7400::{ArrayAttributeEncoding, ArrayAttributeHeader, AttributeType},
writer::v7400::binary::{Error, Result, Writer},
};
mod array;
/// A dummy type for impossible error.
pub(crate) enum ... | true |
28759bca98519c67038e1320562a450ee7681127 | Rust | baylesj/advent-of-code-2019 | /src/day_two.rs | UTF-8 | 1,523 | 3.0625 | 3 | [] | no_license | #[path = "intcode_computer.rs"]
mod intcode_computer;
use intcode_computer::LoadableFromFile;
use intcode_computer::Program;
use intcode_computer::Runnable;
const INPUT_FILENAME: &'static str = "input/day_two.txt";
fn set_program_inputs(program: &mut Program, noun: i64, verb: i64) {
program.buffer[1] = noun;
... | true |
851d032ad9afde0abf2be857c66eaffe6e864a25 | Rust | cilarp/nlp | /2020/exercise/nlp000/src/main.rs | UTF-8 | 146 | 3.328125 | 3 | [] | no_license | fn main() {
let s = "stressed";
let res = rev(s);
println!("{}", res);
}
fn rev(s: &str) -> String {
s.chars().rev().collect()
}
| true |
2fe64f16c050db63c6df1a3633f1d39429390b5b | Rust | BLQ5/cxx | /gen/src/out.rs | UTF-8 | 3,177 | 3.078125 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use crate::gen::include::Includes;
use crate::syntax::namespace::Namespace;
use std::cell::RefCell;
use std::fmt::{self, Arguments, Write};
pub(crate) struct OutFile {
pub namespace: Namespace,
pub header: bool,
pub include: Includes,
pub front: Content,
content: RefCell<Content>,
}
pub struct Con... | true |
92878f1b370cd3385570ca354a1008c48343a073 | Rust | xshade-lang/xshade-parser | /src/ast/block_declaration.rs | UTF-8 | 268 | 2.515625 | 3 | [
"MIT"
] | permissive | use ::ast::*;
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct BlockDeclaration {
pub span: Span,
pub statements: Vec<Statement>,
}
impl Spanned for BlockDeclaration {
fn get_span(&self) -> Span {
self.span
}
}
| true |
90c1a11c8d7356fe95b82533107104ee46335ffb | Rust | bltavares/rs-consul | /src/hyper_wrapper.rs | UTF-8 | 3,784 | 2.671875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | /*
MIT License
Copyright (c) 2021 Roblox
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distrib... | true |
1fb5f82a96e0eb4ca2cc21e4601760d1ad9eee71 | Rust | AHobbyistDev/Cryptopals-Rust | /src/set1/c3.rs | UTF-8 | 586 | 3.296875 | 3 | [] | no_license | use util::cipher::Cipher;
use util::hex::HexParseable;
use util::xor;
// SET 1, CHALLENGE 3: http://cryptopals.com/sets/1/challenges/3/
static IN: &'static str = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736";
pub fn main() {
let ciphertext = IN.parse_hex().unwrap();
let best = xor::f... | true |
ee892e31e5e941256c2a61703bc5adf374b4a29a | Rust | ilovelll/learn-rust-by-example | /ch3-custom-types/src/main.rs | UTF-8 | 3,029 | 3.640625 | 4 | [] | no_license | #[derive(Debug)]
struct Person<'a> {
name: &'a str,
age: u8,
}
struct Nil;
struct Pair(i32, f32);
#[derive(Debug)]
struct Point {
x: f32,
y: f32,
}
#[allow(dead_code)]
#[derive(Debug)]
struct Rectangle {
p1: Point,
p2: Point,
}
fn rect_area(rec: Rectangle) -> f32 {
let Point {x: x1, y:y1} = ... | true |
de37a53c2eb1958e1895a431be1801f54e8d87d1 | Rust | ZekeWK/Linear-System-Solver | /src/matrice.rs | UTF-8 | 6,961 | 3.515625 | 4 | [] | no_license | use MatriceError::*;
#[derive(PartialEq, PartialOrd, Debug)]
pub struct AugMatrice {
rows : Vec<Row>,
width : usize, //Does not inclued augmented matrix
height : usize,
}
impl AugMatrice {
pub fn new(rows : Vec<Row>) -> Result<AugMatrice, MatriceError> {
let height = rows.len();
... | true |
ad1f29df6cb5c6ebd9fcc0cb29376f050efdde05 | Rust | elliotdavies/advent-of-code-2016 | /utils/src/aoc.rs | UTF-8 | 1,528 | 2.921875 | 3 | [] | no_license | use colored::Colorize;
use std::fmt::Debug;
use std::fs;
pub struct Problem<'a, I, O> {
pub input_file: &'a str,
pub parser: fn(&str) -> I,
pub part1_examples: Vec<(&'a str, O)>,
pub part1: fn(I) -> O,
pub part2_examples: Vec<(&'a str, O)>,
pub part2: fn(I) -> O,
}
impl<I, O> Problem<'_, I, O>... | true |
ffd31d5eaf311f10e5b8bbb430be8ab3791f2ba1 | Rust | ros2rust/realsense-rust | /src/kind/extension.rs | UTF-8 | 10,044 | 2.765625 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Possible interface extensions as an enumeration.
use num_derive::{FromPrimitive, ToPrimitive};
use realsense_sys as sys;
/// Enumeration of interface extensions
///
/// `Rs2Extension` is an enumeration type that lists all the possible underlying interfaces that
/// librealsense2 types can be extended to. Most of t... | true |
428283821373a4737e6dbebbbf7aab4380693632 | Rust | abdullahwaqar/leetcode | /70.Climbing_Stairs/src/main.rs | UTF-8 | 443 | 3.15625 | 3 | [] | no_license | struct Solution {}
impl Solution {
pub fn climb_stairs(n: i32) -> i32 {
if n <= 2 {
return n;
}
let mut first_step = 1;
let mut second_step = 2;
for _ in 3..=n {
let next_step = first_step + second_step;
first_step = second_step;
... | true |
f74e75687577945de37515a1dc1a2a553b00bbfb | Rust | Neo-Zhixing/cornell_box | /src/renderer/raygen.rs | UTF-8 | 2,319 | 2.96875 | 3 | [] | no_license | use crate::renderer::Ray;
use crate::scene::Scene;
use glam::{Vec2, Vec3, Vec3A};
use image::RgbaImage;
use rayon::prelude::*;
pub type Pixel = image::Rgba<u8>;
pub fn raygen<F>(scene: &Scene, fragment: F) -> RgbaImage
where
F: Fn(Ray) -> Vec3 + Sync,
{
let (width, height) = scene.resolution;
let num_pixe... | true |
50b5466dc8f5f1cdf62353dc049f332f281fc6f0 | Rust | aabb15768/StellarSQL | /src/component/database.rs | UTF-8 | 1,398 | 3.203125 | 3 | [
"MIT"
] | permissive | use crate::component::table::Table;
use crate::storage::file::File;
use crate::storage::file::FileError;
use std::collections::HashMap;
use std::fmt;
#[derive(Debug, Clone)]
pub struct Database {
pub name: String,
pub tables: HashMap<String, Table>,
}
#[derive(Debug)]
pub enum DatabaseError {
CausedByFile... | true |
ddaba8dd112947b2d3f52defece80f9659c58aa7 | Rust | koivunej/eventstore-tcp | /testclient/src/delete.rs | UTF-8 | 1,895 | 2.625 | 3 | [
"MIT"
] | permissive | use std::io;
use std::cell::RefCell;
use futures::Future;
use tokio_service::Service;
use eventstore_tcp::EventStoreClient;
use eventstore_tcp::builder::DeleteStreamBuilder;
use {Config, Command};
pub struct Delete {
builder: RefCell<Option<DeleteStreamBuilder>>,
}
impl Delete {
pub fn new(builder: DeleteStre... | true |
e87050546624b8ad30e5e5247b828eceee745fb6 | Rust | ForsakenHarmony/smali | /src/dex/asm/instruction.rs | UTF-8 | 15,690 | 2.96875 | 3 | [] | no_license | use color_eyre::{
eyre::{bail, eyre},
Result,
};
use crate::dex::{
asm::{
format::Format,
opcode::{Opcode, VALUE_TO_OPCODE},
},
parser::{Parse, Parser},
};
// trait Instruction {
// fn opcode(&self) -> &Opcode;
// fn code_units(&self) -> u32 {
// self.opcode().format().size() as u32
// }
// }
//
// trai... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.