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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
495b105e42c83b8ad13f40e598671fa67d8c4d67 | Rust | iKurum/leet_code | /rust/src/junior_algorithm/vector/v06.rs | UTF-8 | 807 | 3.53125 | 4 | [] | no_license | #![allow(dead_code)]
struct Solution;
impl Solution {
/// 给定两个数组,编写一个函数来计算它们的交集。
fn intersect(nums1: Vec<i32>, nums2: Vec<i32>) -> Vec<i32> {
let (mut a, mut b) = (nums1, nums2);
a.sort();
b.sort();
let mut result: Vec<i32> = Vec::new();
let (mut r1, mut r2) = (0 as usize, 0 as usize);
whi... | true |
07de021bfcee1aff71fd68f33eca9b464ae249a8 | Rust | liqudefi/bondingVcurve | /src/erc20/erc20_contract.rs | UTF-8 | 5,020 | 3.578125 | 4 | [] | no_license | use std::collections::HashMap;
use crate::common::*;
pub struct ERC20Contract{
pub balances: HashMap<Address, Amount>,
pub allowances: HashMap<Address, HashMap<Address, Amount>>,
pub name: Name,
pub symbol: Symbol,
pub decimals: Decimals,
pub total_supply: TotalSupply,
}
impl ERC20Contr... | true |
e61b2590c1cd6cd8a94c6d1c23c90704d2377af0 | Rust | gnoliyil/fuchsia | /third_party/rust_crates/vendor/gpt-3.0.0/src/macros.rs | UTF-8 | 1,240 | 2.53125 | 3 | [
"MIT",
"BSD-2-Clause"
] | permissive |
#[macro_use]
pub(crate) mod crate_macros {
/// Macro to read an exact buffer
macro_rules! read_exact_buff {
($bufid:ident, $rdr:expr, $buflen:expr) => {
{
let mut $bufid = [0_u8; $buflen];
let _ = $rdr.read_exact(&mut $bufid)?;
$bufid... | true |
878bd8386028bbb064132906ec2f934c85b97d6a | Rust | yk-amarly-20/atcoder_rust | /contest/abc182/src/bin/b.rs | UTF-8 | 1,378 | 3.15625 | 3 | [] | no_license | mod utils {
use std::error::Error;
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code)]
pub fn read_line<T>() -> Result<Vec<T>, Box<dyn Error>>
where
T: FromStr,
T::Err: 'static + Error,
{
let mut line = String::new();
let _ = stdin().read_line(&mut... | true |
53bec5a419ed192d0dabfb03bbc53bfcc02c3b63 | Rust | dbrgn/netchoose-rs | /src/netctl.rs | UTF-8 | 1,278 | 3.421875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! Everything interfacing with netctl.
//!
//! Communication with netctl is done through a subprocess.
use std::process::Command;
#[derive(Debug)]
pub struct Profile {
pub name: String,
pub active: bool,
}
/// Return list of netctl profiles.
pub fn get_profiles() -> Vec<Profile> {
let output = Command::... | true |
78d10844cb3d9650159184dd2c5c5d974c35ae29 | Rust | caitlingao/leetcode_rust | /src/cd0206_reverse_linked_list/mod.rs | UTF-8 | 1,976 | 4.09375 | 4 | [] | no_license | //! Reverse Linked List [leetcode: reverse_linked_list](https://leetcode.com/problems/reverse-linked-list)
//!
//! Reverse a singly linked list.
//!
//! ***Example:***
//!
//! ```
//! Input: 1->2->3->4->5->NULL
//!
//! Output: 5->4->3->2->1->NULL
//! ```
//!
//! ***Follow up:***
//!
//! A linked list can be reversed ei... | true |
6e7152e325d85d3ea694fca7896b6774d40ce8d0 | Rust | manpat/imgui-playground | /toybox-rs/src/gfx/mesh/geom_3d.rs | UTF-8 | 1,646 | 2.71875 | 3 | [] | no_license | use common::*;
use crate::gfx::mesh::{PolyBuilder3D, traits::BuildableGeometry3D};
pub struct Tetrahedron {
basis: Mat3x4,
}
impl Tetrahedron {
pub fn from_matrix(basis: Mat3x4) -> Tetrahedron {
Tetrahedron {basis}
}
pub fn unit() -> Tetrahedron {
Tetrahedron::from_matrix(Mat3x4::identity())
}
}
impl Build... | true |
dc6fe249f3425e14b80c21e6217c4609c16d292f | Rust | Tim-Zhang/rust-protobuf | /protobuf/src/reflect/optional/mod.rs | UTF-8 | 2,290 | 3.171875 | 3 | [
"MIT"
] | permissive | use crate::reflect::runtime_types::RuntimeTypeTrait;
use crate::reflect::ProtobufValue;
use crate::reflect::ReflectEq;
use crate::reflect::ReflectEqMode;
use crate::reflect::ReflectValueRef;
use crate::reflect::RuntimeType;
enum Impl<'a> {
None(RuntimeType),
Some(ReflectValueRef<'a>),
}
/// Singular field fie... | true |
0a65149767fb7614225b99f2d7c085ce0b855679 | Rust | svmk/fund-watch-bot | /src/telegram/action/fund_change_list_action.rs | UTF-8 | 4,168 | 2.546875 | 3 | [] | no_license | use crate::prelude::*;
use crate::telegram::model::action_id::ActionId;
use crate::market::common::model::company_name::CompanyName;
use crate::telegram::model::action_type::ActionType;
use crate::telegram::model::action_route::ActionRoute;
use crate::telegram::action::pager_action::{PagerAction, Page};
use crate::mark... | true |
49f1d4d66e3691323c21ba4a8702612894dd3151 | Rust | yuuki/rlq | /src/ltsv.rs | UTF-8 | 6,066 | 3.09375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::io::{self, BufRead, BufReader, Stdin, stdin};
use std::fs::File;
use std::path::Path;
use std::collections::HashMap;
use error::*;
pub type Record = HashMap<String, String>;
pub type FieldGroupCount = HashMap<String, i32>;
pub enum LineReader {
Stdin(Stdin),
FileIn(BufReader<File>),
}
impl LineRead... | true |
56f4fb1ec8afcbbc77cd31b2fe45547495881a68 | Rust | cprai/yewstack_demo | /post.rs | UTF-8 | 1,493 | 2.765625 | 3 | [
"MIT"
] | permissive | //! ```cargo
//! [dependencies]
//! maud = "*"
//! base64 = "*"
//! ```
extern crate maud;
extern crate base64;
use maud::html;
use base64::encode;
use std::fs::{read, write};
// Beware of data url size limits on certain browsers!!!
fn into_url(data: String, mime_type: &str) -> String {
format!("data:{};base64,{}... | true |
0e34aedb1a0c3e865661c3c57715ef6de28c3036 | Rust | txstate-etc/mediadepot | /src/cas.rs | UTF-8 | 3,357 | 2.65625 | 3 | [
"MIT"
] | permissive | use std::{ env, str, io };
use hyper::error::Error as HyperError;
use http::uri::InvalidUri;
use xml::reader::{EventReader, XmlEvent, Error as XmlError};
use tower_web::extract::{Context, Error, Extract, Immediate};
use tower_web::util::buf_stream::BufStream;
use super::auth::Auth;
//use percent_encoding::{utf8_percent... | true |
d613499adc78a5588cdfc1c234f04ce43dac6a68 | Rust | ajith-herga/vec_impl | /src/stack.rs | UTF-8 | 416 | 3.34375 | 3 | [] | no_license | use vec::MyVec;
pub struct MyStack<T> {
my_vec: MyVec<T>,
}
impl<T> MyStack<T> {
pub fn new() -> Self {
MyStack {
my_vec: MyVec::new(None),
}
}
pub fn push(&mut self, elem: T) {
self.my_vec.push_back(elem);
}
pub fn top(&self) -> Option<&T> {
self.... | true |
260fee8e16c8ed68955d83260a0cffb9571202e5 | Rust | caspervonb/kioto | /src/keyboard.rs | UTF-8 | 3,632 | 3.1875 | 3 | [] | no_license | use crate::sys;
use std::mem;
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum KeyCode {
Apostrophe = 39,
Comma = 44,
Minus = 45,
Period = 46,
Slash = 47,
Zero = 48,
One = 49,
Two = 50,
Three = 51,
Four = 52,
Five = 53,
Six = 54,
Seven = 55,
... | true |
c995a3817fafeb521e97402ee272d37f7ffa10d8 | Rust | wathiede/pbrt | /src/lights/infinite.rs | UTF-8 | 3,105 | 2.53125 | 3 | [
"Apache-2.0"
] | permissive | // Copyright 2020 Google LLC
//
// 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
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in ... | true |
59b25c8cf38c30a3232604d1c5b8691421ad3492 | Rust | youyangy/GraphScope | /research/gaia/gremlin/gremlin_core/src/process/traversal/step/by_key.rs | UTF-8 | 3,287 | 2.578125 | 3 | [
"Apache-2.0",
"BSD-3-Clause",
"LicenseRef-scancode-generic-cla",
"BSL-1.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-elastic-license-2018",
"LicenseRef-scancode-other-permissive"
] | permissive | //
//! Copyright 2020 Alibaba Group Holding Limited.
//!
//! 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 a... | true |
41b5485c3dd1e89816269836afa23db50c1b7454 | Rust | headcrab-rs/headcrab | /tests/runtime_breakpoint.rs | UTF-8 | 5,033 | 3.109375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! This is a basic test for the software breakpoints
//! Here we take a simple rust program, and instrument it using headcrab.
//! Setting breakpoints at a symbol's address, and then checking that we
//! do have the expected state once the breakpoint is hit.
mod test_utils;
#[cfg(target_os = "linux")]
use headcrab::... | true |
04a0ce8499560583cb5ee87e6c3171200fd556c5 | Rust | dowoncha/financial | /src/bin/oanda_practice.rs | UTF-8 | 3,931 | 2.59375 | 3 | [] | no_license | extern crate chrono;
use chrono::prelude::*;
extern crate futures;
use futures::{Future, Stream};
extern crate reqwest;
// extern crate hyper;
// use hyper::{Method, Request};
// use hyper::header::{Authorization, ContentType, Bearer};
// extern crate hyper_tls;
// use hyper_tls::HttpsConnector;
/... | true |
5a7699174fdc4daefc60cc50af99b52561dccfd7 | Rust | iguto/webserver | /src/request_handler/request_handler.rs | UTF-8 | 2,038 | 2.953125 | 3 | [] | no_license | use std::fs::File;
use std::path::{Path, PathBuf};
use std::io::{Read, Write};
use super::request_line::*;
use super::response_header::*;
const NOT_FOUND_HTML: &'static str = r#"
<html>
<head>
<title>Not Found</title>
</head>
<body>
<h1>Not Found</h1>
</body>
"#;
enum RequestError {
NotFound,
Forbidden,
... | true |
a7bbf350d59c5f4862ecbb701cdc1b8cb31bece8 | Rust | ghtyrant/sinfonia-server | /src/audio_engine/engine/messaging.rs | UTF-8 | 8,238 | 2.5625 | 3 | [] | no_license | use std::collections::HashMap;
use std::time::Duration;
use crate::audio_engine::backends::base::AudioBackend;
use crate::audio_engine::engine::error::AudioEngineError;
use crate::audio_engine::engine::AudioEntity;
use crate::audio_engine::engine::{AudioController, AudioEntityState};
use crate::audio_engine::messages:... | true |
740d61da581bf86ef9891a7210e7a3a5ccedb9ae | Rust | rust-lang/rls | /rls/src/actions/diagnostics.rs | UTF-8 | 25,543 | 2.546875 | 3 | [
"MIT",
"LicenseRef-scancode-other-permissive",
"Apache-2.0"
] | permissive | //! Conversion of raw rustc-emitted JSON messages into LSP diagnostics.
//!
//! Data definitions for diagnostics can be found in the Rust compiler for:
//! 1. Internal diagnostics at `src/librustc_errors/diagnostic.rs`.
//! 2. Emitted JSON format at `src/librustc_errors/json.rs`.
use std::collections::HashMap;
use std... | true |
e9aa78e4940e422d81196b33cfdbebcbb6940386 | Rust | cleverhero/PasC | /src/ParserPack/Nodes/if_node.rs | UTF-8 | 1,723 | 2.859375 | 3 | [] | no_license | use GeneratorPack::*;
use std::fmt;
use std::fmt::Display;
use std::rc::Rc;
use ParserPack::Nodes::support::*;
use support::*;
#[derive(Clone)]
pub struct IfNode {
pub cond: Rc<Node>,
pub block: Rc<Node>,
pub else_block: Option<Rc<Node>>,
}
impl IfNode {
pub fn new(
cond: Rc<Node>,
bl... | true |
0bb54b0d4dfcff09a440c4442986b995b4eca486 | Rust | satanja/Hex | /src/heur/sa.rs | UTF-8 | 12,709 | 2.796875 | 3 | [
"MIT"
] | permissive | use super::Heuristic;
use crate::{
graph::{Compressor, Graph, HeuristicReduce},
util::RangeSet,
};
use rand::{
distributions::{Distribution, Uniform},
rngs::StdRng,
Rng, SeedableRng,
};
pub struct SimulatedAnnealing {
graph: Graph,
mapping: Vec<u32>,
conf_vtoi: Vec<Option<usize>>,
c... | true |
f2c64b786913333e3c6eb23ad31656aba65d684c | Rust | mhorvers/worder | /src/main.rs | UTF-8 | 689 | 2.671875 | 3 | [] | no_license | use std::env;
use std::error::Error;
use std::fs::File;
use std::io::BufReader;
mod game;
mod game_rules;
mod io;
fn load_from_file(file: &String) -> Result<Vec<(String, String)>, Box<dyn Error>> {
let file = File::open(file)?;
let reader = BufReader::new(file);
let translations: Vec<(String, String)> = s... | true |
7cd6fd12d10fb2997b5ed66d37951e4b8e21018c | Rust | notify-rs/notify | /examples/pollwatcher_scan.rs | UTF-8 | 1,664 | 3.15625 | 3 | [
"CC0-1.0",
"MIT",
"Apache-2.0",
"LicenseRef-scancode-public-domain"
] | permissive | use notify::{poll::ScanEvent, Config, PollWatcher, RecursiveMode, Watcher};
use std::path::Path;
// Example for the pollwatcher scan callback feature.
// Returns the scanned paths
fn main() {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
let path = std::env::args(... | true |
3144779caf243e573ef67ad0ea3f767f1134726f | Rust | mark-i-m/os1 | /kernel/fs/ofs/mod.rs | UTF-8 | 6,256 | 2.734375 | 3 | [
"MIT"
] | permissive | #![allow(warnings)] // TODO
//! A module for os1 FS (OFS)
pub mod file;
mod hw;
mod internals;
use alloc::arc::Arc;
use core::mem;
use self::file::File;
use self::hw::*;
use self::internals::*;
use super::error::Error;
use io::block::{BlockDataBuffer, BlockDevice};
use sync::Semaphore;
/// A safe handle on the f... | true |
4f6761506cea9120be542a2879a1565037899224 | Rust | drogue-iot/embassy | /embassy-stm32/src/dac/v2.rs | UTF-8 | 8,000 | 2.59375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use crate::dac::{DacPin, Instance};
use crate::gpio::AnyPin;
use crate::pac::dac;
use core::marker::PhantomData;
use embassy::util::Unborrow;
use embassy_extras::unborrow;
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
UnconfiguredChannel,
InvalidValue,
}
pub enum Chan... | true |
b6b639a43887dc8cfdd44709ba30fdf26dd7c554 | Rust | jetli/mdc-rs | /examples/minimal/src/routes/home.rs | UTF-8 | 1,320 | 2.78125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use yew::prelude::*;
use mdc_yew::components::button::Button;
/// Home page
pub struct Home;
impl Component for Home {
type Message = ();
type Properties = ();
fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
Home {}
}
fn update(&mut self, _: Self::Message) -> ShouldRende... | true |
a3a7efe9aca3d7366540e562771a67d06af4c2ab | Rust | dmvict/wMath | /rust/impl/math/adapter/vector/x2/structure.rs | UTF-8 | 2,899 | 2.609375 | 3 | [
"MIT"
] | permissive | //!
//! Implement canonical X2 strcture.
//!
/// Internal namespace.
pub( crate ) mod private
{
use crate::*;
///
/// Vector X2
///
#[ allow( non_camel_case_types ) ]
#[ repr( C ) ]
#[ derive( PartialEq, Copy, Clone, Hash, Default ) ]
pub struct X2
<
Scalar : ScalarInterface,
>
( pub Scalar... | true |
b051a9da9183bf26986aca6652ca21ca49d4ec60 | Rust | KaitaoQiu/openlimits | /crates/openlimits-exchange/src/model/order_filter.rs | UTF-8 | 2,167 | 3.1875 | 3 | [
"BSD-2-Clause"
] | permissive | use rust_decimal::prelude::Decimal;
use serde::Deserialize;
use serde::Serialize;
use super::OrderStatus;
use super::OrderType;
use super::Side;
use std::ops::Range;
/// This struct represents an order
#[derive(Default, Serialize, Deserialize, Clone, Debug)]
#[allow(missing_docs)]
pub struct OrderFilter {
pub mark... | true |
a29aae3b16738725bb7cce7e8d20f5bc3fbd70f1 | Rust | IgaguriMK/raw-nbt | /src/lib.rs | UTF-8 | 9,283 | 2.671875 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #![doc(html_root_url = "https://docs.rs/raw-nbt/0.1.1")]
pub mod decode;
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::fmt;
/// An NBT Value.
#[derive(Debug, Clone, PartialEq)]
pub enum Value {
// basic types
Byte(i8),
Short(i16),
Int(i32),
Long(i64),
Float(f32),
Double(f... | true |
e1510d1d631d1eae34f4179ac0cddbf3b98d993d | Rust | grenewode/advent-of-code-2019 | /day-three/src/main.rs | UTF-8 | 1,881 | 3.765625 | 4 | [] | no_license | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Vector {
pub x: i32,
pub y: i32,
}
impl Vector {
pub const fn new(x: i32, y: i32) -> Self {
Self { x, y }
}
pub const fn up() -> Self {
Self::new(0, 1)
}
pub const fn down() -> Self {
Se... | true |
755d459ee49e4015ba8446df0b1808c0daaf471d | Rust | owtotwo/Simple-Calculator | /src/calculator/expr/integer.rs | UTF-8 | 2,978 | 3.359375 | 3 | [] | no_license | use std::fmt;
use std::error;
use std::error::Error;
use super::operator::Operator;
use super::Result;
pub struct Integer(pub i32);
impl Integer {
pub fn parse(raw_int: &str) -> Result<(Integer, &str)> {
let mut unsigned: u64 = 0;
let is_neg: bool;
let mut rest_of_expr = raw_int.trim_left(... | true |
23cee55aa4657d89e73cca2438758d72ab90b5dc | Rust | czyczk/LeetCode | /rust/lc-387/src/main.rs | UTF-8 | 370 | 2.71875 | 3 | [] | no_license | mod solution;
use solution::Solution;
fn main() {
let s1 = "leetcode".to_owned();
let s2 = "loveleetcode".to_owned();
let s3 = "".to_owned();
// Expecting 0
println!("{}", Solution::first_uniq_char(s1));
// Expecting 2
println!("{}", Solution::first_uniq_char(s2));
// Expecting -1
... | true |
dff9c676875474a00457d190f08e47b9b62e162f | Rust | sebashwa/awman | /src/parsing/doc_structure.rs | UTF-8 | 2,971 | 3.3125 | 3 | [
"MIT"
] | permissive | use nom::{
IResult,
combinator::opt,
sequence::tuple,
bytes::complete::tag,
};
use super::ManfileComponent;
use super::helpers::txt_arg;
use super::styled_text::StyledText;
#[derive(Debug, PartialEq, Eq)]
pub struct PageTitle {
pub title: StyledText,
pub section: Option<StyledText>,
pub fo... | true |
bf41c0f0180d4be96201c92c59472da807fe922b | Rust | JackLiar/rust-dpdk | /rte/src/common/rand.rs | UTF-8 | 566 | 2.84375 | 3 | [] | no_license | //! Pseudo-random Generators in RTE
use ffi;
/// Seed the pseudo-random generator.
///
/// The generator is automatically seeded by the EAL init with a timer
/// value. It may need to be re-seeded by the user with a real random value.
pub fn srand(seed: u64) {
unsafe { ffi::_rte_srand(seed) }
}
/// Get a pseudo... | true |
195c399bef9003a49f40fad62cd34c3037b2a508 | Rust | Axect/Rust | /Library/ndarray_linalg_test/src/main.rs | UTF-8 | 663 | 2.53125 | 3 | [] | no_license | extern crate ndarray;
extern crate ndarray_linalg;
use ndarray::*;
use ndarray_linalg::*;
fn main() {
let a: Array2<f64> = random((3, 3));
println!("{}", a);
let x = solve().unwrap();
println!("{}", x);
factorize().unwrap();
}
fn solve() -> Result<Array1<f64>, error::LinalgError> {
let a: Arr... | true |
956b618a3fbf71e88085d1f8a76c6586730a1332 | Rust | icyJoseph/codejam-js | /src/trouble_sort/src/trouble_sort.rs | UTF-8 | 1,657 | 3.34375 | 3 | [] | no_license | use std::io;
type Res<T> = Result<T, Box<dyn std::error::Error>>;
fn nxt() -> String {
let mut input = String::new();
match io::stdin().read_line(&mut input) {
Ok(_) => input,
_ => panic!("Error reading line"),
}
}
fn ptc<T: std::str::FromStr>() -> T {
match nxt().trim().parse::<T>() ... | true |
6718b7db7d404168bc4c769204e3f622a68bed3b | Rust | kreako/edts4c | /backend/src/db/competencies.rs | UTF-8 | 9,479 | 2.78125 | 3 | [
"MIT"
] | permissive | use crate::db::cycles::Cycle;
use crate::db::evaluations::Evaluation;
use crate::db_log::Logger;
use crate::Result;
use diesel;
use diesel::dsl::max;
use diesel::PgConnection;
use diesel::{ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl};
use serde::{Deserialize, Serialize};
#[derive(Queryable, Serialize, ... | true |
8f70563f31c2a33c2646e8e4db5249706b893296 | Rust | tristanisham/ModMark | /src/lib.rs | UTF-8 | 2,510 | 3.1875 | 3 | [] | no_license | use std::io::Write;
use std::env;
use std::error::Error;
use std::fs;
use std::fs::File;
use pulldown_cmark::{html, Options, Parser};
pub struct Config {
pub conv_from: String,
pub conv_to: String,
}
impl Config {
pub fn new(mut args: env::Args) -> Result<Config, &'static str> {
//skips first arg ... | true |
21512b18082e4a9bb586ec4f07bd1121e2e831f1 | Rust | jam1garner/cargo-mextk | /src/paths.rs | UTF-8 | 1,343 | 2.578125 | 3 | [] | no_license | use dirs_next::home_dir;
use std::path::{Path, PathBuf};
use std::fs;
pub fn mextk_bin_dir() -> PathBuf {
mextk_dir()
.push_join("bin")
.push_join("mextk")
.ensure_exists()
}
pub fn mextk_deps_dir() -> PathBuf {
mextk_dir()
.push_join("deps")
.ensure_exists()
}
pub fn... | true |
b239e982a2bfc92db2d642f88a4afa775d83f0cb | Rust | book-resources/rustlernen | /10-Benutzerdefinierte Typen/programmtext-120.rs | UTF-8 | 98 | 3 | 3 | [] | no_license | struct Point(i32, i32);
fn main() {
let p = Point(0, 1);
println!("({}, {})", p.0, p.1);
} | true |
021360af35bce1e85147f4190f4e50495596b679 | Rust | greglearns/openapi-codegen-rs | /tests/openapi-examples/link-example/src/link_example/models/pullrequest.rs | UTF-8 | 2,930 | 2.640625 | 3 | [] | no_license | #[allow(unused_imports)]
use serde_json::Value;
#[allow(unused_imports)]
use std::borrow::Borrow;
#[allow(unused_imports)]
use super::*;
#[derive(Debug, Default, Serialize, Deserialize, PartialEq)]
pub struct r#Pullrequest {
#[serde(rename = "author", skip_serializing_if = "Option::is_none")]
r#author: Optio... | true |
f7e28f44c41d4cd8ce8158cb1b65a495b315d33f | Rust | rust-chainblock/mitrid-core | /src/io/network/server/server.rs | UTF-8 | 3,860 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | //! # Server
//!
//! `server` is the module providing the trait implemented by network servers.
use std::thread;
use std::sync::{Arc, Mutex};
use base::Result;
use base::size::{ConstantSize, VariableSize};
use base::Serializable;
use base::Datable;
use base::{Eval, EvalMut};
use io::store::Store;
use io::network::tra... | true |
0c888fc095446f35ce8cefb027c6529396bea40d | Rust | peeper35/certdiff | /src/main.rs | UTF-8 | 6,835 | 2.765625 | 3 | [] | no_license | extern crate clap;
extern crate json;
extern crate colored;
use clap::{Arg, App};
use colored::*;
use std::env;
use std::fs;
use std::fs::File;
use std::io::Write;
use std::{thread, time};
use std::io::BufReader;
use std::io::prelude::*;
fn main() {
// clap thang
let arg_matches = App::new("certdiff")
... | true |
5e90d1c3b82715f4364b5d441b0f6ae70656375e | Rust | hotacium/algorithms-and-data-structures | /src/search/binary.rs | UTF-8 | 1,008 | 3.640625 | 4 | [] | no_license |
use std::cmp::Ordering;
pub fn binary_search<T: Ord>(item: &T, src: &[T]) -> Option<usize> {
let mut left = 0; // inclusive
let mut right = src.len(); // exclusive
while left < right {
let mid = (left + right)/2;
match item.cmp(&src[mid]) {
Ordering::Less => righ... | true |
e30e69dbbe68b18284f16b343e78cb697a7dd024 | Rust | rozaliev/rustler | /src/service/service.rs | UTF-8 | 3,688 | 2.984375 | 3 | [] | no_license | use future::Future;
use std::marker::PhantomData;
pub trait Service<Req,Resp,E>
where Resp: Send+'static,
E: Send+'static {
fn apply(&self, r: Req) -> Future<Resp, E>;
}
struct ConstService<Req, Resp, E>
where Resp: Send + 'static,
E: Send + 'static
{
f: Box<Fn(Req) -> Future<Resp, E> + Send... | true |
f7657272bab1a7e9e52440f19e596fc3c56877e4 | Rust | troligtvis/pong | /src/world.rs | UTF-8 | 3,063 | 3.015625 | 3 | [] | no_license | use crate::{
graphics, na,
player::{Player, PADDLE_WIDTH_HALF},
Ball, Context, Controls, KeyCode,
};
pub const PADDING: f32 = 40.;
pub struct World {
pub player_1: Player,
pub player_2: Player,
pub ball: Ball,
max_score: i32,
dt: f32,
}
impl World {
pub fn new(ctx: &mut Context, m... | true |
4ab5904cbe68b4a81dc446c2366bd560f52f76a5 | Rust | typst/typst | /crates/typst/src/geom/color.rs | UTF-8 | 14,776 | 3.078125 | 3 | [
"Apache-2.0",
"Bitstream-Vera",
"CC-BY-4.0",
"OFL-1.1",
"LicenseRef-scancode-gust-font-1.0",
"BSD-3-Clause",
"LicenseRef-scancode-ubuntu-font-1.0",
"0BSD",
"LicenseRef-scancode-free-unknown",
"LicenseRef-scancode-public-domain",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer"
] | permissive | use ecow::{eco_format, EcoString};
use std::str::FromStr;
use super::*;
use crate::diag::bail;
use crate::eval::{cast, Array, Cast};
/// A color in a dynamic format.
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
pub enum Color {
/// An 8-bit luma color.
Luma(LumaColor),
/// An 8-bit RGBA color.
Rgba(Rgb... | true |
014ef0652aada347484fc2dc2f48dc92ce336949 | Rust | efb9-860a-e752-0dac/serpent | /src/keys.rs | UTF-8 | 5,046 | 2.875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use crate::tables::*;
use crate::transforms::*;
use crate::PHI;
use crate::ROUNDS;
pub(crate) type Key = [u8; 32];
pub(crate) type Subkey = u128;
pub(crate) type Subkeys = [Subkey; ROUNDS + 1];
pub(crate) fn parse_text_key(key: &str) -> Option<Vec<u8>> {
if !key.is_ascii() {
return None;
}
let byt... | true |
12d9610d60f9f741ecfedec10baa7a6edc46d020 | Rust | jdon/shakespearean_pokemon | /src/client/pokemon_client.rs | UTF-8 | 4,867 | 3.140625 | 3 | [] | no_license | use super::client_error::ClientError;
use serde::{Deserialize, Serialize};
use surf::{Client, StatusCode};
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Pokemon {
pub id: i64,
pub name: String,
pub is_legendary: bool,
pub habitat: Habitat,
pub flavor_text_entries: Vec<FlavorTextEnt... | true |
73ec428845a56877be8680b34baed6037827b422 | Rust | vidstige/pandemic | /src/cards.rs | UTF-8 | 4,185 | 3.78125 | 4 | [] | no_license | use std::cmp;
// Stack - push is_empty, etc
// Deck - draw
// Hand - iterate, discard to deck
pub trait Stack<T>: Sized {
fn is_empty(&self) -> bool;
fn len(&self) -> usize;
fn push(&mut self, card: T);
}
pub trait Deck<T>: Stack<T> {
fn draw(&mut self) -> Option<T>;
fn draw_bottom(&mut self) -> ... | true |
63ad29ca98d36bf552f751bfd3e0bb53b30d01cd | Rust | salahgapr5/web | /confidential-identity/src/claim_proofs.rs | UTF-8 | 11,074 | 2.8125 | 3 | [
"Apache-2.0"
] | permissive | //! The `claim_proofs` library contains API for generating
//! claim proofs and verifying them as part of the
//! Asset Granularity Unique Identity project.
//!
//! ```
//! use confidential_identity::{claim_proofs::{Provider, Investor, Verifier},
//! CddClaimData, ScopeClaimData, ScopeClaimProof, ProviderTrait, Inv... | true |
e5bbdc6aaa24ade56fec22f3998923b86675e04c | Rust | cesbo/bitwrap | /tests/bits.rs | UTF-8 | 1,484 | 3.125 | 3 | [] | no_license | use bitwrap::*;
#[test]
fn test_bits() {
const DATA: &[u8] = &[0xA5, 0x5B, 0x12, 0x34, 0xF5, 0x67, 0x89, 0xAF];
#[derive(Default, Debug, BitWrap)]
struct Packet {
#[bitfield(6)] rshift_test: u8,
#[bitfield(4)] lshift_rshift_test: u8,
#[bitfield(6)] skip_1: u8,
#[bitfield(1... | true |
e1ebbf06bb68b1f2f44eea2d0d3dc4d50c9d9b45 | Rust | SmartsquareGmbH/weekly-coding-challenge | /prime-factors-kata/rust/jkrafczyk/src/main.rs | UTF-8 | 2,036 | 2.953125 | 3 | [] | no_license | extern crate hyper;
use hyper::{Body, Request, Response, Server, Method, StatusCode};
use hyper::rt::Future;
use hyper::service::service_fn_ok;
const PATH_PREFIX: &str = "/generate/";
const ERROR_RESPONSE: &str = "\"ERROR\"";
fn factor(mut n: u32) -> Vec<u32> {
let mut result = Vec::new();
if n < 2 {
... | true |
7f5e58b545059c1945ccf808305e58d3d4f01441 | Rust | LiveSplit/livesplit-core | /src/util/byte_parsing.rs | UTF-8 | 2,584 | 2.84375 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use core::mem;
use bytemuck::AnyBitPattern;
pub mod big_endian {
use super::strip_pod;
use bytemuck_derive::{Pod, Zeroable};
use core::fmt;
#[derive(Copy, Clone, Pod, Zeroable)]
#[repr(transparent)]
pub struct U16(pub [u8; 2]);
impl fmt::Debug for U16 {
fn fmt(&self, f: &mut fmt:... | true |
396bcb984d12305e6c1e3499beadb9f701652e63 | Rust | harpsword/tex-rs | /src/tex_the_program/section_0232.rs | UTF-8 | 6,160 | 2.625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //! @ We initialize most things to null or undefined values. An undefined font
//! is represented by the internal code |font_base|.
//!
//! However, the character code tables are given initial values based on the
//! conventional interpretation of ASCII code. These initial values should
//! not be changed when \TeX\ is... | true |
a60e531885871549b5a4856707c8b78c53d3fe00 | Rust | calbro7/Pleco | /pleco/src/lib.rs | UTF-8 | 3,449 | 2.9375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! A blazingly fast chess library.
//!
//! This package is separated into two parts. Firstly, the board representation & associated functions
//! (the current crate, `pleco`), and secondly, the AI implementations using these chess foundations,
//! [pleco_engine](https://crates.io/crates/pleco_engine).
//!
//! The gene... | true |
6f2adfcf797f7ab16f33f8bda332c39e6cf855b0 | Rust | cdupuis1/flotsam | /rust/shell/src/main.rs | UTF-8 | 3,606 | 3.828125 | 4 | [] | no_license | //
// Basic shell written in Rust
//
use std::io::{self, Write};
use std::process;
use std::process::Command;
use execute::Execute;
use std::env;
// Remove newline from end of string if it exists
//
// str_to_chomp - Input string
//
// Returns string with newline removed (or same string if none exists)
fn chomp(mut st... | true |
346919d3beb773e2beb005e8edb07dbaf7735dc1 | Rust | fewensa/rttp | /rttp_client/src/types/para.rs | UTF-8 | 6,110 | 3.3125 | 3 | [
"MIT"
] | permissive | use std::collections::HashMap;
use crate::types::FormData;
use crate::types::ParaType::FORM;
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum ParaType {
URL,
FORM,
}
#[derive(Clone, Debug)]
pub struct Para {
name: String,
value: Option<String>,
type_: ParaType,
array: bool
}
pub trait IntoPara {
... | true |
4c09cc8c9becca769bb8e87120d79ec8a71c46f6 | Rust | feather-rs/tonks | /src/try_default.rs | UTF-8 | 316 | 2.734375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | pub trait TryDefault {
fn try_default() -> Option<Self>
where
Self: Sized;
}
impl<T> TryDefault for T {
default fn try_default() -> Option<Self> {
None
}
}
impl<T> TryDefault for T
where
T: Default,
{
fn try_default() -> Option<Self> {
Some(Self::default())
}
}
| true |
104421c7090f2d5fb3d54dd91c8c693c918beb7a | Rust | mich101mich/hierarchical_pathfinding | /src/grid/a_star.rs | UTF-8 | 4,557 | 3.171875 | 3 | [
"MIT"
] | permissive | use super::{HeuristicElement, Path};
use crate::{neighbors::Neighborhood, Point, PointMap};
use std::cmp::Ordering;
use std::collections::BinaryHeap;
pub fn a_star_search<N: Neighborhood>(
neighborhood: &N,
mut valid: impl FnMut(Point) -> bool,
mut get_cost: impl FnMut(Point) -> isize,
start: Point,
... | true |
fc72183d3339314992f05e4046a98c7571403c05 | Rust | inickt/cs4500-wortham | /Fish/Common/src/common/gamestate.rs | UTF-8 | 22,072 | 3.15625 | 3 | [] | no_license | //! The gamestate module defines the SharedGameState that will be
//! serialized by the server and sent to each client - informing
//! them of any updates to the game. The GameState itself is a
//! shared mutable pointer which in the client is shared between
//! the communication layer (TBD) and the ui layer. It repres... | true |
1bf85b4a166907961bdc45fc9118fccc80e48c4c | Rust | keichiri/djcrab | /src/cli.rs | UTF-8 | 1,852 | 3.28125 | 3 | [] | no_license | use std::io;
use std::io::{Write, BufRead};
use std::sync::mpsc::Sender;
use std::thread::sleep;
use std::time::Duration;
use ::command::Command;
pub(super) struct CLI {
channel: Sender<Command>,
}
impl CLI {
pub(super) fn new(channel: Sender<Command>) -> Self {
CLI {
channel: channel,
... | true |
a5dd2847e402043a6ccc041f78ef65145459e8f5 | Rust | przprz/exercism-rust | /isbn-verifier/src/lib.rs | UTF-8 | 1,002 | 3.609375 | 4 | [] | no_license | const ISBN_LENGTH: usize = 10;
#[derive(Debug)]
enum Isbn {
Invalid,
}
/// Determines whether the supplied string is a valid ISBN number
pub fn is_valid_isbn(isbn: &str) -> bool {
let chars: Vec<char> = isbn.chars().filter(|&ch| ch != '-').collect();
if chars.len() != ISBN_LENGTH {
return false;
... | true |
0eecd1b69bd84aa5ad6129435326958732096673 | Rust | devillies/rust_lang_project | /src/main.rs | UTF-8 | 616 | 3.28125 | 3 | [] | no_license | use std::io;
use std::cmp::Ordering;
use rand::Rng;
fn main(){
println!("guess the number\n" );
let secret_number = rand::thread_rng().gen_range(1,101);
loop{
println!("input a number");
let mut guess = String::new();
io::stdin().read_line(&mut guess).expect("failed to readline");
let guess: u32 = guess... | true |
02d37f0b523580bd0850cfe6c42320fa64ccc91d | Rust | pensivearchitect/rq | /serde-protobuf/src/descriptor.rs | UTF-8 | 34,043 | 3.8125 | 4 | [
"Apache-2.0"
] | permissive | //! Dynamic descriptors for protocol buffer schemata.
//!
//! The descriptors are optimized for read performance, i.e. to be used by a parser to parse actual
//! protocol buffer data.
//!
//! They can be constructed either from pre-compiled protocol buffer-serialized descriptors as
//! defined in [`descriptor.proto`][1... | true |
eaed09186e62a1b35e4b3fd980829523f6805bef | Rust | liuwei1025/learn-rust | /src/first_word.rs | UTF-8 | 314 | 2.890625 | 3 | [] | no_license | // String长度可变 str是不可变长度的string
/**
* https://kaisery.github.io/trpl-zh-cn/ch04-03-slices.html#%E5%AD%97%E7%AC%A6%E4%B8%B2-slice
*/
pub fn first_word(s: &String) -> &str {
for (i, &item) in s.as_bytes().iter().enumerate() {
if item == b' ' {
return &s[0..i]
}
}
&s[..]
}
| true |
d0626a1d4f16ec273275e3b969d6fde72f8552e4 | Rust | danielSanchezQ/poorman_linked_list | /src/lib.rs | UTF-8 | 3,081 | 3.828125 | 4 | [] | no_license | use std::ops::{Index};
#[derive(Debug)]
struct Node<T> {
next : Option<Box<Node<T>>>,
value : Box<T>,
}
impl<T> Node<T> {
pub fn new(val : T, next : Option<Box<Node<T>>>) -> Self {
Node {
next,
value : Box::new(val)
}
}
pub fn get(&self) -> &T {
sel... | true |
6bccc4a6b1acbdc2d1b344d7446ae9ff645233ba | Rust | aoowweenn/mmd-rs | /src/traits.rs | UTF-8 | 1,526 | 2.71875 | 3 | [
"BSD-3-Clause"
] | permissive | use nom::{IResult, le_f32};
use types::{Vec2, Vec3, Vec4};
pub trait Parse<VEC = Self> {
const COUNT: usize;
type ARRAY;
fn parse(input: &[u8]) -> IResult<&[u8], VEC>
where
VEC: From<Self::ARRAY>,
{
Self::nom_macro(input).map(|o| VEC::from(o))
}
fn nom_macro(input: &[u8]) ... | true |
da59a214af38536f1f070cd38b7273e12bb65f89 | Rust | zmitchell/pngme | /src/chunk.rs | UTF-8 | 7,236 | 3.125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | use crate::chunk_type::{ChunkType, ChunkTypeError};
use crc::crc32::checksum_ieee;
use std::convert::TryFrom;
use std::error::Error;
use std::fmt;
use std::io::Read;
#[derive(Debug)]
pub enum ChunkError {
UTF8Error(std::string::FromUtf8Error),
ChunkTypeError(ChunkTypeError),
InvalidCRC(u32, u32),
Lengt... | true |
8830d3587c432836181b7a81914c7560dfc52899 | Rust | afrase/lib-ruby-parser | /src/source/source_line.rs | UTF-8 | 405 | 3 | 3 | [
"MIT"
] | permissive | #[derive(Debug, Clone, Default)]
pub struct SourceLine {
pub start: usize,
pub end: usize,
pub ends_with_eof: bool,
}
impl SourceLine {
pub fn len(&self) -> usize {
self.end - self.start
}
pub fn line_end(&self) -> usize {
let mut result = self.end;
if !self.ends_with_e... | true |
3a7bca6fad60a182f8e0d7fa1769d6f6b569f65f | Rust | sabahtalateh/tokio_chat_server | /examples/future.rs | UTF-8 | 3,215 | 3.828125 | 4 | [] | no_license | use futures::task::spawn;
use futures::{task, AndThen, Async, Future, Poll, Map};
/// Our own type `MyFut`
#[derive(Debug)]
struct MyFut {
n: i32,
}
impl MyFut {
fn new() -> Self {
MyFut { n: 0 }
}
}
/// Implement `Future` for `MyFut`
impl Future for MyFut {
/// Return type of `future` is `i3... | true |
e794de41a52554b94be1f2b90dcabbc1ecc705f6 | Rust | PurpleBabar/wu | /src/wu/lexer/token.rs | UTF-8 | 2,843 | 3.453125 | 3 | [
"MIT"
] | permissive | use colored::Colorize;
use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum TokenType {
Int,
Float,
Str,
Char,
Bool,
Identifier,
Keyword,
Symbol,
Operator,
Whitespace,
EOL,
EOF,
}
impl fmt::Display for TokenType {
fn fmt (&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Tok... | true |
f45ed4219e1cb900de0d8cf67387a1489258751a | Rust | alpiro/fdec | /tests/u32_5_25_full.rs | UTF-8 | 55,633 | 2.859375 | 3 | [
"MIT"
] | permissive | #[macro_use]
extern crate fdec;
fdec32! {
module decimal,
name Decimal,
length 5,
scale 25
}
use decimal::*;
fn test_str(d: Decimal, expected: &str) {
assert_eq!(d.to_string(), expected);
}
#[cfg(test)]
mod basic {
use super::decimal::*;
#[test]
fn test_nan() {
let nan = Dec... | true |
3cda9d19a12cc34f2e748801d4e3c9b8b8769e4a | Rust | aterlo/afxdp-rs | /src/buf.rs | UTF-8 | 1,245 | 2.875 | 3 | [
"Apache-2.0"
] | permissive | /// The Buf trait represents a packet buffer.
/// A trait is used so that an implementation can be provided that enables building and testing packet
/// pipelines without needing the AF_XDP infrastructure.
pub trait Buf<T>
where
T: std::default::Default,
{
/// Returns a reference to the u8 slice of the buffer
... | true |
b156bc0a5ec81cfe82f6bb4063f099ba86396834 | Rust | jireva/editspace | /src/bin/cluster.rs | UTF-8 | 2,956 | 2.765625 | 3 | [] | no_license | use std::env;
use std::io::{self, prelude::*, BufReader};
use std::process;
fn main() -> io::Result<()> {
let (distance, min_count, max_error_fraction) = parse_args(env::args());
let trie = trie_from_stdin();
let mut stdout = io::stdout();
let mut stderr = io::stderr();
for ix in trie.iter_words() {
let word ... | true |
f4def6cf5dcd232ab348252699fd464e2ef4b308 | Rust | maximeborges/svd2rust_efm32gg990 | /src/aes.rs | UTF-8 | 3,368 | 2.515625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use vcell::VolatileCell;
#[doc = r" Register block"]
#[repr(C)]
pub struct RegisterBlock {
#[doc = "0x00 - Control Register"]
pub ctrl: CTRL,
#[doc = "0x04 - Command Register"]
pub cmd: CMD,
#[doc = "0x08 - Status Register"]
pub status: STATUS,
#[doc = "0x0c - Interrupt Enable Register"]
... | true |
c9b8ed6487309e140fd1a1aa3acf3042780fc0c2 | Rust | ia7ck/competitive-programming | /AtCoder/virtual-contest/joya-no-kane-2021/src/bin/090/main.rs | UTF-8 | 1,192 | 2.625 | 3 | [] | no_license | use input_i_scanner::InputIScanner;
use mod_int::ModInt998244353;
fn main() {
let stdin = std::io::stdin();
let mut _i_i = InputIScanner::from(stdin.lock());
macro_rules! scan {
(($($t: ty),+)) => {
($(scan!($t)),+)
};
($t: ty) => {
_i_i.scan::<$t>() as $t
... | true |
3227db1dbe156f5210d385f12a7d449fd4e4c74e | Rust | truelossless/crocolang | /src/ast/node/var_call_node.rs | UTF-8 | 397 | 2.671875 | 3 | [
"MIT"
] | permissive | use crate::{
ast::{AstNode, BackendNode},
token::CodePos,
};
/// a node holding a variable reference
#[derive(Clone)]
pub struct VarCallNode {
pub name: String,
pub code_pos: CodePos,
}
impl VarCallNode {
pub fn new(name: String, code_pos: CodePos) -> Self {
VarCallNode { name, code_pos }
... | true |
5c0d9ce34064a9c147dc72ed4f91f2f62ba7e138 | Rust | IThawk/rust-project | /rust-master/src/test/ui/issues/issue-2590.rs | UTF-8 | 225 | 2.671875 | 3 | [
"MIT",
"LicenseRef-scancode-other-permissive",
"Apache-2.0",
"BSD-3-Clause",
"BSD-2-Clause",
"NCSA"
] | permissive | struct Parser {
tokens: Vec<isize> ,
}
trait Parse {
fn parse(&self) -> Vec<isize> ;
}
impl Parse for Parser {
fn parse(&self) -> Vec<isize> {
self.tokens //~ ERROR cannot move out
}
}
fn main() {}
| true |
0910da8857bcc0a8b51633283c81c824757b7a3e | Rust | thomasmathew365/rust-for-ts-devs | /src/generic_functions.rs | UTF-8 | 663 | 3.6875 | 4 | [] | no_license | // Functions can have generics too, but usually you will need
// to add *trait bounds* to be able to act on parameters with
// generic types...
pub fn clone<T: Clone>(item: &T) -> T {
// We need to know `T` implements `Clone` to know that
// `item` has a `clone()` method:
item.clone()
}
// Little sidestep... | true |
232e40328e6df69d99bd7d3a33ee03c0039bd060 | Rust | Jamiewu2/godot-networking-example | /rust-lib/src/lib.rs | UTF-8 | 861 | 2.859375 | 3 | [] | no_license | use gdnative::prelude::*;
/// The HelloWorld "class"
#[derive(NativeClass)]
#[inherit(Node)]
pub struct HelloWorld;
// You may add any number of ordinary `impl` blocks as you want. However, ...
impl HelloWorld {
/// The "constructor" of the class.
fn new(_owner: &Node) -> Self {
HelloWorld
}
}
//... | true |
c85b4eb0f7d1926538456f9fc478d7c6d463e929 | Rust | akki2825/huobi-chain | /services/riscv/src/error.rs | UTF-8 | 1,819 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | use derive_more::{Display, From};
use protocol::traits::ServiceResponse;
#[derive(Debug, Display, From)]
pub enum ServiceError {
#[display(fmt = "Method {} can not be invoke with call", _0)]
NotInExecContext(String),
#[display(fmt = "Contract {} not exists", _0)]
ContractNotFound(String),
#[displ... | true |
8a1cf69c76cae43078a1c5e5e076c64ace51b4e6 | Rust | Tokap/rust-sandbox | /yoursql/src/patsql/write.rs | UTF-8 | 4,550 | 3.203125 | 3 | [] | no_license | use mysql::{Pool};
use json;
/*******************************************************/
/*********** Return Struct for Writing ***************/
/*****************************************************/
#[derive(Debug, Default, PartialEq, Eq)]
pub struct SqlWriteReturn {
last_save_id: u64,
affected_rows: u64,
... | true |
a89c32c85b07384fe2cc0fca5fd1edd705aed901 | Rust | phR0ze/cnx | /cnx-contrib/src/widgets/battery/battery_linux.rs | UTF-8 | 5,518 | 3.125 | 3 | [
"MIT"
] | permissive | use anyhow::{anyhow, Context, Error, Result};
use cnx::text::{Attributes, Color, Text};
use cnx::widgets::{Widget, WidgetStream};
use std::fs::File;
use std::io::Read;
use std::str::FromStr;
use std::time::Duration;
use tokio::time;
use tokio_stream::wrappers::IntervalStream;
use tokio_stream::StreamExt;
/// Represent... | true |
21b5c15cccc8db9d4d3a07ecaabdb43b16046b8a | Rust | stouset/secrets | /src/boxed.rs | UTF-8 | 29,848 | 3.34375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | #![allow(unsafe_code)]
use crate::ffi::sodium;
use crate::traits::*;
use std::cell::Cell;
use std::fmt::{self, Debug};
use std::ptr::NonNull;
use std::slice;
use std::thread;
/// The page protection applied to the memory underlying a [`Box`].
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Prot {
/// Any attem... | true |
45c65fa3e4f809305f9374079e08064efe2dbc7d | Rust | narodnik/nym | /sfw-provider/sfw-provider-requests/src/responses.rs | UTF-8 | 4,539 | 3.078125 | 3 | [] | no_license | use crate::AuthToken;
use std::convert::TryInto;
#[derive(Debug)]
pub enum ProviderResponseError {
MarshalError,
UnmarshalError,
UnmarshalErrorInvalidLength,
}
pub trait ProviderResponse
where
Self: Sized,
{
fn to_bytes(&self) -> Vec<u8>;
fn from_bytes(bytes: &[u8]) -> Result<Self, ProviderRes... | true |
423ce79b097f0f0bbee067f1c869e862ac70f796 | Rust | yxw0087/Rust-Programming-Projects | /ExplicitRef_yxw0087/explicit_ref_ast.rs | UTF-8 | 10,545 | 3.015625 | 3 | [] | no_license | use std::rc::Rc;
use std::fmt;
use explicit_ref_ast::ExplicAST::*;
#[derive(Debug,Clone)]
pub enum ExplicAST { // a node in an AST
ConstExp(i32),
Boolean(bool),
PlusExp(Rc<ExplicAST>, Rc<ExplicAST>),
DiffExp(Rc<ExplicAST>, Rc<ExplicAST>),
IsZeroExp(Rc<ExplicAST>),
IfExp(Rc<ExplicAST>, Rc<Explic... | true |
d80ff475df9561b4dba8d54cdead4d1e695eb79b | Rust | fosterdill/rust-gol | /src/engine/rules.rs | UTF-8 | 1,167 | 3.171875 | 3 | [] | no_license | #[derive(Debug)]
pub struct Rules;
#[derive(Debug, Clone, Copy)]
pub enum LifeState {
Alive,
Dead,
}
pub trait HasLifeState {
fn get_life_state(&self) -> &LifeState;
}
pub trait ConwayRules<T> {
fn get_next_life_state(&self, &T, Vec<T>) -> LifeState;
}
impl <T: HasLifeState> ConwayRules<T> for Rules... | true |
3cd6b484a75ac76abdf563818e053157645b32aa | Rust | udoprog/rune | /crates/rune-modules/src/test.rs | UTF-8 | 3,202 | 3.03125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //! `std::experiments` module for the [Rune Language].
//!
//! [Rune Language]: https://rune-rs.github.io
//!
//! ## Usage
//!
//! Add the following to your `Cargo.toml`:
//!
//! ```toml
//! rune-modules = { version = "0.12.0", features = ["test"] }
//! ```
//!
//! Install it into your context:
//!
//! ```rust
//! # fn... | true |
d0fb35d5a2edb6fb8a94b6fbca7c77c045d673fd | Rust | mortifiers/memflow-cli | /memflow-cli/src/commands/gdb/attach.rs | UTF-8 | 1,522 | 2.53125 | 3 | [
"MIT"
] | permissive | use crate::dispatch::*;
use crate::Config;
use clap::{App, Arg, ArgMatches, SubCommand};
use log::trace;
use memflow_daemon::request;
pub const COMMAND_STR: &str = "attach";
const CONNECTION_ID: &str = "CONNECTION_ID";
const PROCESS_ID: &str = "PROCESS_ID";
const ADDRESS: &str = "ADDRESS";
pub fn command_definiti... | true |
c563c3eee04150581cf73d382b70a6f9eb2e856b | Rust | nehaghaty/rust_sandbox | /variables/src/main.rs | UTF-8 | 2,097 | 3.984375 | 4 | [] | no_license | use std::io;
fn main() {
// // println!("Hello, world!");
let condition= false;
//if with let
let number = if condition{5} else {7};
println!("the number is {}", number);
// returning vlauyes from loops
let mut count = 0;
let res = loop{
if count ==5{
break count+1;
... | true |
de50417d23cc88d8f57d932502bb7d7af0ffb7b2 | Rust | ColinPitrat/RustMisc | /evolution/src/graph.rs | UTF-8 | 6,794 | 2.75 | 3 | [] | no_license | use crate::dc::DrawingContext;
use sdl2::pixels::Color;
use sdl2::rect::Point;
//use std::convert::TryFrom;
const MARGIN : u32 = 20;
const LEGEND_MARGIN : i32 = 5;
const TITLE_HEIGHT : u32 = 50;
const TOP_MARGIN : u32 = 2*MARGIN + TITLE_HEIGHT; // Margin above and below the title
const DOWN_MARGIN : u32 = MARGIN;
cons... | true |
5e84311cf5be0791ead912102d723bb61b6aa980 | Rust | swuecho/tools_written_in_rust | /fastq_spliter/src/main.rs | UTF-8 | 754 | 2.5625 | 3 | [] | no_license | extern crate bio;
extern crate rand;
use rand::thread_rng;
use bio::io::fastq;
use rand::Rng;
use std::env;
fn filter_records(in_file: &str, out_file: &str) {
let reader = fastq::Reader::from_file(in_file).unwrap();
let mut writer = fastq::Writer::to_file(out_file).unwrap();
let mut rng = thread_rng();
... | true |
b41a61df95c7cf1242046da8a3991e408b839ee1 | Rust | k-kapp/learn-rust | /gitstats/src/main.rs | UTF-8 | 1,114 | 2.90625 | 3 | [] | no_license | mod stats;
use std::env;
fn main() {
let args = env::args().collect::<Vec<String> >();
if args.len() != 2 {
println!("Usage: gitstats <dirname>");
return;
}
let mut dirname: &str = args[1].as_str();
let mut fromback = 0;
let mut iter = dirname.chars().rev();
while ite... | true |
3e39c9b1f25b3dced0674de594706adeb8987c40 | Rust | matheusnoronha/PAA | /src/backtrack_sudoku/main.rs | UTF-8 | 4,843 | 3.703125 | 4 | [
"MIT"
] | permissive | // Utilidades pra facilitar o uso das matrizes
// ############################################################################
type Matriz = Vec<Vec<i32>>;
fn get_pos(matriz: &Matriz, linha: usize, coluna: usize) -> i32 {
matriz[linha - 1][coluna - 1]
}
fn set_pos(matriz: &mut Matriz, linha: usize, coluna: usize... | true |
191edc73bfc8ab3f956362de88c0b06f186a3255 | Rust | robmikh/goldsrc-asset-viewer | /wad3parser/src/lib.rs | UTF-8 | 15,300 | 2.53125 | 3 | [
"MIT"
] | permissive | extern crate bincode;
extern crate byteorder;
extern crate image;
extern crate serde;
use std::fs::File;
use std::io::{BufReader, Cursor, Read, Seek, SeekFrom};
use std::path::Path;
use std::str;
use byteorder::{LittleEndian, ReadBytesExt};
use serde::Deserialize;
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Te... | true |
d762d134527416926c92a15aad15450795756154 | Rust | EFanZh/LeetCode | /src/problem_0908_smallest_range_i/iterative.rs | UTF-8 | 1,385 | 3.125 | 3 | [] | no_license | pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //
impl Solution {
fn min_max(nums: &[i32]) -> (i32, i32) {
let mut iter = nums.iter().copied();
let mut min = iter.next().unwrap();
let mut max = min;... | true |
94b7e36a3ee74717aac412177d9ddf0057ee157c | Rust | brigand/glint | /src/figlet.rs | UTF-8 | 4,526 | 3.328125 | 3 | [
"MIT"
] | permissive | use crossterm::style::{self, Color};
use std::fs::read_to_string;
use std::io;
use std::path::Path;
const CHAR_OFFSET: usize = 32;
#[derive(Debug, Clone)]
pub struct Figlet {
height: usize,
chars: Vec<Char>,
}
#[derive(Debug, Clone)]
pub struct Char {
width: usize,
text: Vec<String>,
}
impl Figlet {... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.