file_name large_stringlengths 4 69 | prefix large_stringlengths 0 26.7k | suffix large_stringlengths 0 24.8k | middle large_stringlengths 0 2.12k | fim_type large_stringclasses 4
values |
|---|---|---|---|---|
io.rs | use alloc::boxed::Box;
use core::result;
use std::error;
/// A specialized [`Result`](../result/enum.Result.html) type for I/O
/// operations.
///
/// This type is broadly used across `std::io` for any operation which may
/// produce an error.
///
/// This typedef is generally used to avoid writing out `io::Error` dir... | (&mut self) -> Result<()> {
Ok(())
}
}
pub trait Read {
fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
}
| flush | identifier_name |
io.rs | use alloc::boxed::Box;
use core::result;
use std::error;
/// A specialized [`Result`](../result/enum.Result.html) type for I/O
/// operations.
///
/// This type is broadly used across `std::io` for any operation which may
/// produce an error.
///
/// This typedef is generally used to avoid writing out `io::Error` dir... | /// ```
//#[stable(feature = "rust1", since = "1.0.0")]
pub type Result<T> = result::Result<T, Error>;
/// The error type for I/O operations of the `Read`, `Write`, `Seek`, and
/// associated traits.
///
/// Errors mostly originate from the underlying OS, but custom instances of
/// `Error` can be created with crafted... | /// Ok(buffer)
/// } | random_line_split |
challenge13.rs | use aes::Aes128;
use aes::{chunks_count, BLOCK_SIZE};
use crate::errors::*;
use crate::prefix_suffix_oracles::Oracle;
use crate::prefix_suffix_oracles::Oracle13;
use super::challenge12::prefix_plus_suffix_length;
use super::prefix_length;
// The following function works under the single assumption that the target v... | () -> Result<()> {
let oracle = Oracle13::new()?;
let prefix_len = prefix_length(&oracle)?;
let (prefix_chunks_count, prefix_fill_len) = chunks_count(prefix_len);
let target_cleartext = b"admin".pad();
let mut input = vec![0; prefix_fill_len];
input.extend_from_slice(&target_cleartext);
//... | run | identifier_name |
challenge13.rs | use aes::Aes128;
use aes::{chunks_count, BLOCK_SIZE};
use crate::errors::*;
use crate::prefix_suffix_oracles::Oracle;
use crate::prefix_suffix_oracles::Oracle13;
use super::challenge12::prefix_plus_suffix_length;
use super::prefix_length;
// The following function works under the single assumption that the target v... | compare_eq((chunks_count + 1) * BLOCK_SIZE, ciphertext.len())?;
// Replace last block with target_last_block
ciphertext[chunks_count * BLOCK_SIZE..].copy_from_slice(target_last_block);
oracle.verify_solution(&ciphertext)
}
| {
let oracle = Oracle13::new()?;
let prefix_len = prefix_length(&oracle)?;
let (prefix_chunks_count, prefix_fill_len) = chunks_count(prefix_len);
let target_cleartext = b"admin".pad();
let mut input = vec![0; prefix_fill_len];
input.extend_from_slice(&target_cleartext);
// Determine the ci... | identifier_body |
challenge13.rs | use aes::Aes128;
use aes::{chunks_count, BLOCK_SIZE};
use crate::errors::*;
use crate::prefix_suffix_oracles::Oracle;
use crate::prefix_suffix_oracles::Oracle13;
use super::challenge12::prefix_plus_suffix_length;
use super::prefix_length;
// The following function works under the single assumption that the target v... |
// The following input is chosen in such a way that the cleartext in oracle looks as follows:
// email=\0... \0 || \0...\0&uid=10&role= || user <- padding ->
let (chunks_count, fill_len) = chunks_count(prefix_plus_suffix_length(&oracle)?);
let mut ciphertext = oracle.encrypt(&vec![0; fill_len + "user".... | .encrypt(&input)?
.split_off(prefix_chunks_count * BLOCK_SIZE)[0..BLOCK_SIZE]; | random_line_split |
svg.rs | use gio::MemoryInputStream;
use glib::Bytes;
use predicates::prelude::*;
use predicates::reflection::{Case, Child, PredicateReflection, Product};
use std::cmp;
use std::fmt;
use librsvg::{CairoRenderer, Length, Loader, LoadingError, SvgHandle};
/// Checks that the variable of type [u8] can be parsed as a SVG file.
#[... | (self: Self, width: Length, height: Length) -> DetailPredicate<Self> {
DetailPredicate::<Self> {
p: self,
d: Detail::Size(Dimensions {
w: width,
h: height,
}),
}
}
}
fn svg_from_bytes(data: &[u8]) -> Result<SvgHandle, LoadingError>... | with_size | identifier_name |
svg.rs | use gio::MemoryInputStream;
use glib::Bytes;
use predicates::prelude::*;
use predicates::reflection::{Case, Child, PredicateReflection, Product};
use std::cmp;
use std::fmt;
use librsvg::{CairoRenderer, Length, Loader, LoadingError, SvgHandle};
/// Checks that the variable of type [u8] can be parsed as a SVG file.
#[... |
fn find_case<'a>(&'a self, _expected: bool, data: &[u8]) -> Option<Case<'a>> {
match svg_from_bytes(data) {
Ok(_) => None,
Err(e) => Some(Case::new(Some(self), false).add_product(Product::new("Error", e))),
}
}
}
impl PredicateReflection for SvgPredicate {}
impl fmt::... | {
svg_from_bytes(data).is_ok()
} | identifier_body |
svg.rs | use gio::MemoryInputStream;
use glib::Bytes;
use predicates::prelude::*;
use predicates::reflection::{Case, Child, PredicateReflection, Product};
use std::cmp;
use std::fmt;
use librsvg::{CairoRenderer, Length, Loader, LoadingError, SvgHandle};
/// Checks that the variable of type [u8] can be parsed as a SVG file.
#[... | impl PredicateReflection for SvgPredicate {}
impl fmt::Display for SvgPredicate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "is an SVG")
}
}
/// Extends a SVG Predicate by a check for its size
#[derive(Debug)]
pub struct DetailPredicate<SvgPredicate> {
p: SvgPredicate,
d... | random_line_split | |
roxor.rs | use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use std::process;
const PREVIEW_LEN: usize = 50;
#[derive(Debug, PartialEq)]
struct Match {
offset: usize,
key: u8,
preview: String,
}
fn main() {
let args: Vec<String> = env::args().skip(1).collect();
if args.len() < ... | (ciphertext: &[u8], crib: &[u8]) -> Vec<Match> {
let mut matches: Vec<Match> = Vec::new();
for (i, x) in ciphertext.iter().enumerate() {
let mut old_key = x ^ crib[0];
let mut j = 1;
while j < crib.len() && (i + j) < ciphertext.len() {
let key = ciphertext[i + j] ^ crib[j];
... | attack_cipher | identifier_name |
roxor.rs | use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use std::process;
const PREVIEW_LEN: usize = 50;
#[derive(Debug, PartialEq)]
struct Match {
offset: usize,
key: u8,
preview: String,
}
fn main() {
let args: Vec<String> = env::args().skip(1).collect();
if args.len() < ... | offset: i,
key,
preview,
});
}
}
}
matches
}
#[cfg(test)]
mod tests {
use super::{attack_cipher, Match};
struct Test {
ciphertext: &'static [u8],
crib: &'static [u8],
matches: Vec<M... | {
let mut matches: Vec<Match> = Vec::new();
for (i, x) in ciphertext.iter().enumerate() {
let mut old_key = x ^ crib[0];
let mut j = 1;
while j < crib.len() && (i + j) < ciphertext.len() {
let key = ciphertext[i + j] ^ crib[j];
if key != old_key {
... | identifier_body |
roxor.rs | use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use std::process;
const PREVIEW_LEN: usize = 50;
#[derive(Debug, PartialEq)]
struct Match {
offset: usize,
key: u8,
preview: String,
}
fn main() {
let args: Vec<String> = env::args().skip(1).collect();
if args.len() < ... | else { '.' })
.collect();
matches.push(Match {
offset: i,
key,
preview,
});
}
}
}
matches
}
#[cfg(test)]
mod tests {
use super::{attack_cipher, Match};
struct Test {
... | { x as char } | conditional_block |
roxor.rs | use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use std::process;
const PREVIEW_LEN: usize = 50;
#[derive(Debug, PartialEq)]
struct Match {
offset: usize,
key: u8,
preview: String,
}
fn main() {
let args: Vec<String> = env::args().skip(1).collect();
if args.len() < ... | ciphertext: b"needle in haystack",
crib: b"needle",
matches: vec![
Match { offset: 0, key: 0, preview: "needle in haystack".to_string() },
],
},
Test {
ciphertext: b"a needle, another needle",
... | },
Test { | random_line_split |
parser_any_macro.rs | // from src/libsyntax/ext/tt/macro_rules.rs
use std::cell::RefCell;
use syntax::parse::parser::Parser;
use syntax::parse::token;
use syntax::ast;
use syntax::ptr::P;
use syntax::ext::base::MacResult;
use syntax::util::small_vector::SmallVector;
pub struct ParserAnyMacro<'a> {
parser: RefCell<Parser<'a>>,
}
impl<... |
/// Make sure we don't have any tokens left to parse, so we don't
/// silently drop anything. `allow_semi` is so that "optional"
/// semicolons at the end of normal expressions aren't complained
/// about e.g. the semicolon in `macro_rules! kapow { () => {
/// panic!(); } }` doesn't get picked up b... | {
ParserAnyMacro {
parser: RefCell::new(p)
}
} | identifier_body |
parser_any_macro.rs | // from src/libsyntax/ext/tt/macro_rules.rs
use std::cell::RefCell; | use syntax::parse::token;
use syntax::ast;
use syntax::ptr::P;
use syntax::ext::base::MacResult;
use syntax::util::small_vector::SmallVector;
pub struct ParserAnyMacro<'a> {
parser: RefCell<Parser<'a>>,
}
impl<'a> ParserAnyMacro<'a> {
pub fn new(p: Parser<'a>) -> ParserAnyMacro<'a> {
ParserAnyMacro {
... | use syntax::parse::parser::Parser; | random_line_split |
parser_any_macro.rs | // from src/libsyntax/ext/tt/macro_rules.rs
use std::cell::RefCell;
use syntax::parse::parser::Parser;
use syntax::parse::token;
use syntax::ast;
use syntax::ptr::P;
use syntax::ext::base::MacResult;
use syntax::util::small_vector::SmallVector;
pub struct ParserAnyMacro<'a> {
parser: RefCell<Parser<'a>>,
}
impl<... | (self: Box<ParserAnyMacro<'a>>) -> Option<SmallVector<P<ast::Item>>> {
let mut ret = SmallVector::zero();
while let Some(item) = self.parser.borrow_mut().parse_item() {
ret.push(item);
}
self.ensure_complete_parse(false);
Some(ret)
}
fn make_impl_items(self: ... | make_items | identifier_name |
loop_def.rs |
// loop operation
// store temp values for loop name and refill addresses
use super::ItemID;
use super::vm_code::CodeCollection;
pub struct Loop {
pub name: Option<String>,
pub continue_addr: usize,
pub break_addrs: Vec<usize>,
}
pub struct LoopCollection {
loops: Vec<Loop>,
pub r... |
}
_ => (),
}
}
return None;
}
} | {
lp.break_addrs.push(break_addr);
return Some(());
} | conditional_block |
loop_def.rs | // loop operation
// store temp values for loop name and refill addresses
use super::ItemID;
use super::vm_code::CodeCollection;
pub struct Loop {
pub name: Option<String>,
pub continue_addr: usize,
pub break_addrs: Vec<usize>,
}
pub struct LoopCollection {
loops: Vec<Loop>,
| pub ret_type: ItemID, // so it is not only loop collection but a jump statement context storage
}
impl LoopCollection {
pub fn new() -> LoopCollection {
LoopCollection{
loops: Vec::new(),
ret_type: ItemID::new_invalid(),
}
}
pub fn push_loop(&mut... | random_line_split | |
loop_def.rs |
// loop operation
// store temp values for loop name and refill addresses
use super::ItemID;
use super::vm_code::CodeCollection;
pub struct Loop {
pub name: Option<String>,
pub continue_addr: usize,
pub break_addrs: Vec<usize>,
}
pub struct LoopCollection {
loops: Vec<Loop>,
pub r... | () -> LoopCollection {
LoopCollection{
loops: Vec::new(),
ret_type: ItemID::new_invalid(),
}
}
pub fn push_loop(&mut self, name: Option<String>, continue_addr: usize) {
self.loops.push(Loop{ name: name, continue_addr: continue_addr, break_addrs: Vec:... | new | identifier_name |
loop_def.rs |
// loop operation
// store temp values for loop name and refill addresses
use super::ItemID;
use super::vm_code::CodeCollection;
pub struct Loop {
pub name: Option<String>,
pub continue_addr: usize,
pub break_addrs: Vec<usize>,
}
pub struct LoopCollection {
loops: Vec<Loop>,
pub r... |
// Panic on empty contents
pub fn pop_and_refill(&mut self, refill_adder: usize, codes: &mut CodeCollection) {
let last = self.loops.pop().unwrap();
for break_addr in last.break_addrs {
codes.refill_addr(break_addr, refill_adder);
}
}
pub fn get_last_loop_c... | {
self.loops.push(Loop{ name: name, continue_addr: continue_addr, break_addrs: Vec::new() })
} | identifier_body |
cache.rs | /* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::collections::HashMap;
use std::collections::hash_map::{Occupied, Vacant};
use rand::Rng;
use std::hash::{... |
cache.insert(1, Cell::new("one"));
assert!(cache.find(&1).is_some());
assert!(cache.find(&2).is_none());
cache.find_or_create(&2, |_v| { Cell::new("two") });
assert!(cache.find(&1).is_some());
assert!(cache.find(&2).is_some());
}
pub struct LRUCache<K, V> {
entries: Vec<(K, V)>,
cache... | random_line_split | |
cache.rs | /* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::collections::HashMap;
use std::collections::hash_map::{Occupied, Vacant};
use rand::Rng;
use std::hash::{... |
}
impl<K: Clone + PartialEq, V: Clone> Cache<K,V> for LRUCache<K,V> {
fn insert(&mut self, key: K, val: V) {
if self.entries.len() == self.cache_size {
self.entries.remove(0);
}
self.entries.push((key, val));
}
fn find(&mut self, key: &K) -> Option<V> {
match s... | {
self.entries.iter()
} | identifier_body |
cache.rs | /* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::collections::HashMap;
use std::collections::hash_map::{Occupied, Vacant};
use rand::Rng;
use std::hash::{... | (&mut self) {
self.entries.clear();
}
}
impl<K,V> HashCache<K,V> where K: Clone + PartialEq + Eq + Hash, V: Clone {
pub fn find_equiv<'a,Sized? Q>(&'a self, key: &Q) -> Option<&'a V> where Q: Hash + Equiv<K> {
self.entries.find_equiv(key)
}
}
#[test]
fn test_hashcache() {
let mut cach... | evict_all | identifier_name |
init-res-into-things.rs | // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | { x: r }
#[unsafe_destructor]
impl Drop for r {
fn drop(&mut self) {
self.i.set(self.i.get() + 1)
}
}
fn r(i: Gc<Cell<int>>) -> r {
r {
i: i
}
}
fn test_box() {
let i = box(GC) Cell::new(0i);
{
let _a = box(GC) r(i);
}
assert_eq!(i.get(), 1);
}
fn test_rec() ... | Box | identifier_name |
init-res-into-things.rs | // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... |
fn test_tag() {
enum t {
t0(r),
}
let i = box(GC) Cell::new(0i);
{
let _a = t0(r(i));
}
assert_eq!(i.get(), 1);
}
fn test_tup() {
let i = box(GC) Cell::new(0i);
{
let _a = (r(i), 0i);
}
assert_eq!(i.get(), 1);
}
fn test_unique() {
let i = box(GC) C... | }
assert_eq!(i.get(), 1);
} | random_line_split |
nibbleslice.rs | // Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.... | + if is_leaf { 0x20 } else { 0 });
while i < l {
r.push(self.at(i) * 16 + self.at(i + 1));
i += 2;
}
r
}
}
impl<'a> PartialEq for NibbleSlice<'a> {
fn eq(&self, them: &Self) -> bool {
self.len() == them.len() && self.starts_with(them)
}
}
impl<'a> PartialOrd for NibbleSlice<'a> {
fn partial_cmp(&se... | { 0 } | conditional_block |
nibbleslice.rs | // Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.... |
}
impl<'a> PartialEq for NibbleSlice<'a> {
fn eq(&self, them: &Self) -> bool {
self.len() == them.len() && self.starts_with(them)
}
}
impl<'a> PartialOrd for NibbleSlice<'a> {
fn partial_cmp(&self, them: &Self) -> Option<Ordering> {
let s = min(self.len(), them.len());
let mut i = 0usize;
while i < s {
... | {
let l = min(self.len(), n);
let mut r = Bytes::with_capacity(l / 2 + 1);
let mut i = l % 2;
r.push(if i == 1 { 0x10 + self.at(0) } else { 0 } + if is_leaf { 0x20 } else { 0 });
while i < l {
r.push(self.at(i) * 16 + self.at(i + 1));
i += 2;
}
r
} | identifier_body |
nibbleslice.rs | // Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.... | (&self, i: usize) -> u8 {
let l = self.data.len() * 2 - self.offset;
if i < l {
if (self.offset + i) & 1 == 1 { self.data[(self.offset + i) / 2] & 15u8 } else { self.data[(self.offset + i) / 2] >> 4 }
} else {
let i = i - l;
if (self.offset_encode_suffix + i) & 1 == 1 { self.data_encode_suffix[(self.offs... | at | identifier_name |
nibbleslice.rs | // Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.... | where 'a: 'view,
{
/// Create a new nibble slice with the given byte-slice.
pub fn new(data: &'a [u8]) -> Self {
NibbleSlice::new_offset(data, 0)
}
/// Create a new nibble slice with the given byte-slice with a nibble offset.
pub fn new_offset(data: &'a [u8], offset: usize) -> Self {
NibbleSlice {
data... | }
impl<'a, 'view> NibbleSlice<'a> | random_line_split |
common.rs | // Copyright 2014 The html5ever Project Developers. See the
// COPYRIGHT file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>,... |
pub use self::NodeEnum::{Document, Doctype, Text, Comment, Element};
/// The different kinds of nodes in the DOM.
#[derive(Show)]
pub enum NodeEnum {
/// The `Document` itself.
Document,
/// A `DOCTYPE` with name, public id, and system id.
Doctype(String, String, String),
/// A text node.
Te... |
use collections::vec::Vec;
use collections::string::String;
use string_cache::QualName; | random_line_split |
common.rs | // Copyright 2014 The html5ever Project Developers. See the
// COPYRIGHT file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>,... | {
/// The `Document` itself.
Document,
/// A `DOCTYPE` with name, public id, and system id.
Doctype(String, String, String),
/// A text node.
Text(String),
/// A comment.
Comment(String),
/// An element with attributes.
Element(QualName, Vec<Attribute>),
}
| NodeEnum | identifier_name |
node.rs |
use std::convert::From;
use std::io::Write;
use super::serializer::Serializer;
use string_cache::QualName;
pub struct Attr<'a>(&'a QualName, &'a str);
impl<'a> From<(&'a QualName, &'a str)> for Attr<'a> {
fn | ((key, value): (&'a QualName, &'a str)) -> Attr {
Attr(key, value)
}
}
impl<'a, 'b: 'a> From<&'a (&'b QualName, &'b str)> for Attr<'b> {
fn from(&(key, value): &'a (&'b QualName, &'b str)) -> Attr<'b> {
Attr(key, value)
}
}
pub struct NodeSerializer<'a, 'b: 'a, 'w: 'b, W: 'w + Write> {
... | from | identifier_name |
node.rs | use std::convert::From;
use std::io::Write;
use super::serializer::Serializer;
use string_cache::QualName;
pub struct Attr<'a>(&'a QualName, &'a str);
impl<'a> From<(&'a QualName, &'a str)> for Attr<'a> {
fn from((key, value): (&'a QualName, &'a str)) -> Attr {
Attr(key, value)
}
}
impl<'a, 'b: 'a>... | attrs.into_iter().map(|a| {
let a = a.into();
(a.0, a.1)
}));
NodeSerializer {
name: Some(name),
serializer: self.serializer,
}
... | -> NodeSerializer<'a, 'd, 'w, W>
where I: Iterator<Item = II>,
II: Into<Attr<'i>>
{
self.serializer.start_elem(name.clone(), | random_line_split |
node.rs |
use std::convert::From;
use std::io::Write;
use super::serializer::Serializer;
use string_cache::QualName;
pub struct Attr<'a>(&'a QualName, &'a str);
impl<'a> From<(&'a QualName, &'a str)> for Attr<'a> {
fn from((key, value): (&'a QualName, &'a str)) -> Attr {
Attr(key, value)
}
}
impl<'a, 'b: 'a... |
}
pub fn new_node_ser<'a, 'b: 'a, 'w: 'b, W>(s: &'a mut Serializer<'b, 'w, W>)
-> NodeSerializer<'a, 'b, 'w, W>
where W: 'w + Write
{
NodeSerializer {
name: None,
serializer: s,
}
}
| {
match self.name {
Some(ref name) => self.serializer.end_elem(name.clone()),
None => (),
}
} | identifier_body |
projection-no-regions-closure.rs | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... |
#![allow(warnings)]
#![feature(rustc_attrs)]
trait Anything { }
impl<T> Anything for T { }
fn with_signature<'a, T, F>(x: Box<T>, op: F) -> Box<dyn Anything + 'a>
where F: FnOnce(Box<T>) -> Box<dyn Anything + 'a>
{
op(x)
}
#[rustc_regions]
fn no_region<'a, T>(x: Box<T>) -> Box<dyn Anything + 'a>
where
... | // Tests closures that propagate an outlives relationship to their
// creator where the subject is a projection with no regions (`<T as
// Iterator>::Item`, to be exact). | random_line_split |
projection-no-regions-closure.rs | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | <'a, T, F>(x: Box<T>, op: F) -> Box<dyn Anything + 'a>
where F: FnOnce(Box<T>) -> Box<dyn Anything + 'a>
{
op(x)
}
#[rustc_regions]
fn no_region<'a, T>(x: Box<T>) -> Box<dyn Anything + 'a>
where
T: Iterator,
{
with_signature(x, |mut y| Box::new(y.next()))
//~^ ERROR the associated type `<T as std::... | with_signature | identifier_name |
projection-no-regions-closure.rs | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... |
#[rustc_regions]
fn outlives_region<'a, 'b, T>(x: Box<T>) -> Box<dyn Anything + 'a>
where
T: 'b + Iterator,
'b: 'a,
{
with_signature(x, |mut y| Box::new(y.next()))
}
fn main() {}
| {
with_signature(x, |mut y| Box::new(y.next()))
//~^ ERROR the associated type `<T as std::iter::Iterator>::Item` may not live long enough
} | identifier_body |
unwind.rs | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Stack unwinding
// Implementation of Rust stack unwinding
//
// For background on e... | // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | random_line_split | |
unwind.rs | // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | (msg: Box<Any:Send>,
file: &'static str,
line: uint) ->! {
let mut task;
{
let msg_s = match msg.as_ref::<&'static str>() {
Some(s) => *s,
None => match msg.as_ref::<String>() {
Some(s) => s.as_slice(),
N... | begin_unwind_inner | identifier_name |
unwind.rs | // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | closure();
}
}
extern {
// Rust's try-catch
// When f(...) returns normally, the return value is null.
// When f(...) throws, the return value is a pointer to the caught
// exception object.
fn rust_try(f: extern "C... | {
use raw::Closure;
use libc::{c_void};
unsafe {
let closure: Closure = mem::transmute(f);
let ep = rust_try(try_fn, closure.code as *c_void,
closure.env as *c_void);
if !ep.is_null() {
rtdebug!("caught {}", (*ep)... | identifier_body |
unwind.rs | // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... |
else { // cleanup phase
unsafe {
__gcc_personality_v0(version, actions, exception_class, ue_header,
context)
}
}
}
}
// ARM EHABI uses a slightly different personality routine signature,
// but otherwise works the same.... | { // search phase
uw::_URC_HANDLER_FOUND // catch!
} | conditional_block |
static_priv_by_default.rs | // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | () {}
}
mod foo {
pub static a: int = 0;
pub fn b() {}
pub struct c;
pub enum d {}
pub struct A(());
impl A {
fn foo() {}
}
// these are public so the parent can reexport them.
pub static reexported_a: int = 0;
pub fn reexported_b() {}
pub struct reexported_c;
... | foo | identifier_name |
static_priv_by_default.rs | // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | pub fn b() {}
pub struct c;
pub enum d {}
static i: int = 0;
fn j() {}
struct k;
enum l {} | pub use foo::reexported_d as h;
}
pub static a: int = 0; | random_line_split |
issue-10465.rs | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | ;
impl A for B { fn foo(&self) {} }
pub mod c {
use b::B;
fn foo(b: &B) {
b.foo(); //~ ERROR: does not implement any method in scope named
}
}
}
fn main() {}
| B | identifier_name |
issue-10465.rs | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... |
pub mod c {
use b::B;
fn foo(b: &B) {
b.foo(); //~ ERROR: does not implement any method in scope named
}
}
}
fn main() {} | impl A for B { fn foo(&self) {} } | random_line_split |
issue-10465.rs | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | }
pub mod c {
use b::B;
fn foo(b: &B) {
b.foo(); //~ ERROR: does not implement any method in scope named
}
}
}
fn main() {}
| {} | identifier_body |
ir.rs | /*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
use graphql_ir::*;
use intern::string_key::{StringKey, StringKeyMap, StringKeySet};
use relay_transforms::{DependencyMap, Resolve... | dependency_graph,
base_definition_names,
*parent,
);
}
}
}
// Recursively add all descendants of current node into the `result`
fn add_descendants(
result: &mut StringKeyMap<ExecutableDefinition>,
dependency_graph: &StringKeyMap<Node>,
... | {
if !visited.insert(key) {
return;
}
let parents = match dependency_graph.get(&key) {
None => {
panic!("Fragment {:?} not found in IR.", key);
}
Some(node) => &node.parents,
};
if parents.is_empty() {
if !base_definition_names.contains(&key) {
... | identifier_body |
ir.rs | /*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
use graphql_ir::*;
use intern::string_key::{StringKey, StringKeyMap, StringKeySet};
use relay_transforms::{DependencyMap, Resolve... | (
definitions: Vec<ExecutableDefinition>,
base_definition_names: StringKeySet,
changed_names: StringKeySet,
implicit_dependencies: &DependencyMap,
schema: &SDLSchema,
) -> Vec<ExecutableDefinition> {
if changed_names.is_empty() {
return vec![];
}
// For each executable definitio... | get_reachable_ir | identifier_name |
ir.rs | /*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
use graphql_ir::*;
use intern::string_key::{StringKey, StringKeyMap, StringKeySet};
use relay_transforms::{DependencyMap, Resolve... |
let parents = match dependency_graph.get(&key) {
None => {
panic!("Fragment {:?} not found in IR.", key);
}
Some(node) => &node.parents,
};
if parents.is_empty() {
if!base_definition_names.contains(&key) {
add_descendants(result, dependency_graph, ke... | {
return;
} | conditional_block |
ir.rs | /*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
use graphql_ir::*; | use relay_transforms::{DependencyMap, ResolverFieldFinder};
use schema::SDLSchema;
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::fmt;
struct Node {
ir: Option<ExecutableDefinition>,
parents: Vec<StringKey>,
children: Vec<StringKey>,
}
impl fmt::Debug for Node {
fn fmt(... | use intern::string_key::{StringKey, StringKeyMap, StringKeySet}; | random_line_split |
closure.rs | build::*;
use trans::callee::{self, ArgVals, Callee, TraitItem, MethodData};
use trans::cleanup::{CleanupMethods, CustomScope, ScopeId}; | use trans::common::*;
use trans::datum::{self, Datum, rvalue_scratch_datum, Rvalue, ByValue};
use trans::debuginfo::{self, DebugLoc};
use trans::declare;
use trans::expr;
use trans::monomorphize::{self, MonoId};
use trans::type_of::*;
use middle::ty::{self, ClosureTyper};
use middle::subst::Substs;
use session::config:... | random_line_split | |
closure.rs | ::*;
use trans::callee::{self, ArgVals, Callee, TraitItem, MethodData};
use trans::cleanup::{CleanupMethods, CustomScope, ScopeId};
use trans::common::*;
use trans::datum::{self, Datum, rvalue_scratch_datum, Rvalue, ByValue};
use trans::debuginfo::{self, DebugLoc};
use trans::declare;
use trans::expr;
use trans::monomo... | <'blk,'tcx>(self, bcx: Block<'blk, 'tcx>, arg_scope: ScopeId)
-> Block<'blk, 'tcx>
{
match self {
ClosureEnv::NotClosure => bcx,
ClosureEnv::Closure(freevars) => {
if freevars.is_empty() {
bcx
} else {
... | load | identifier_name |
pixel_buffer.rs | /*!
Pixel buffers are buffers that contain two-dimensional texture data.
Contrary to textures, pixel buffers are stored in a client-defined format. They are used
to transfer data to or from the video memory, before or after being turned into a texture.
*/
use std::borrow::Cow;
use std::cell::Cell;
use std::ops::{Deref... |
}
// TODO: remove this hack
#[doc(hidden)]
pub fn store_infos<T>(b: &PixelBuffer<T>, dimensions: (u32, u32)) where T: PixelValue {
b.dimensions.set(Some(dimensions));
}
| {
self.buffer.get_buffer_id()
} | identifier_body |
pixel_buffer.rs | /*!
Pixel buffers are buffers that contain two-dimensional texture data.
Contrary to textures, pixel buffers are stored in a client-defined format. They are used
to transfer data to or from the video memory, before or after being turned into a texture.
*/
use std::borrow::Cow;
use std::cell::Cell;
use std::ops::{Deref... | (&mut self) -> &mut BufferView<[T]> {
&mut self.buffer
}
}
// TODO: rework this
impl<T> GlObject for PixelBuffer<T> where T: PixelValue {
type Id = gl::types::GLuint;
fn get_id(&self) -> gl::types::GLuint {
self.buffer.get_buffer_id()
}
}
// TODO: remove this hack
#[doc(hidden)]
pub f... | deref_mut | identifier_name |
pixel_buffer.rs | /*!
Pixel buffers are buffers that contain two-dimensional texture data.
Contrary to textures, pixel buffers are stored in a client-defined format. They are used
to transfer data to or from the video memory, before or after being turned into a texture.
*/
use std::borrow::Cow;
use std::cell::Cell;
use std::ops::{Deref... | pub struct PixelBuffer<T> where T: PixelValue {
buffer: BufferView<[T]>,
dimensions: Cell<Option<(u32, u32)>>,
}
impl<T> PixelBuffer<T> where T: PixelValue {
/// Builds a new buffer with an uninitialized content.
pub fn new_empty<F>(facade: &F, capacity: usize) -> PixelBuffer<T> where F: Facade {
... | /// Buffer that stores the content of a texture.
///
/// The generic type represents the type of pixels that the buffer contains. | random_line_split |
vtable_writer.rs | /* | *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distribut... | * Copyright 2018 Google Inc. All rights reserved. | random_line_split |
vtable_writer.rs | /*
* Copyright 2018 Google Inc. All rights reserved.
*
* 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 applica... |
/// Gets an object field offset from the vtable. Only used for debugging.
///
/// Note that this expects field offsets (which are like pointers), not
/// field ids (which are like array indices).
#[inline(always)]
pub fn get_field_offset(&self, vtable_offset: VOffsetT) -> VOffsetT {
le... | {
emplace_scalar::<VOffsetT>(&mut self.buf[SIZE_VOFFSET..2 * SIZE_VOFFSET], n);
} | identifier_body |
vtable_writer.rs | /*
* Copyright 2018 Google Inc. All rights reserved.
*
* 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 applica... | (&mut self, n: VOffsetT) {
emplace_scalar::<VOffsetT>(&mut self.buf[SIZE_VOFFSET..2 * SIZE_VOFFSET], n);
}
/// Gets an object field offset from the vtable. Only used for debugging.
///
/// Note that this expects field offsets (which are like pointers), not
/// field ids (which are like arra... | write_object_inline_size | identifier_name |
LPS.rs | pub fn longest_palindrome(s: String) -> String {
let mut s = s.as_bytes().to_vec();
let mut d = s.clone();
d.reverse();
let mut largest_len = 0;
let mut result = String::new();
loop {
if s.len() == 0 || s.len() < largest_len {
break;
}
let (a, b) = inner_loo... |
let (b, size) = inner_loop2(ss, start, end);
if b {
if size.unwrap() > largest_size {
largest_size = size.unwrap();
record_start = start;
}
}
}
}
//println!("{}, {}", record_start, largest_size... | {
break;
} | conditional_block |
LPS.rs | pub fn longest_palindrome(s: String) -> String | }
result
}
/// find palindrome, return length, start index
fn inner_loop(s: &Vec<u8>, d: &Vec<u8>) -> (usize, String) {
//println!("here: {:?}, {:?}", s, d);
let mut length = s.len();
let mut offset = 0;
let mut flag = true;
loop {
flag = true;
if length == 0 {
... | {
let mut s = s.as_bytes().to_vec();
let mut d = s.clone();
d.reverse();
let mut largest_len = 0;
let mut result = String::new();
loop {
if s.len() == 0 || s.len() < largest_len {
break;
}
let (a, b) = inner_loop(&s, &d);
if a > largest_len {
... | identifier_body |
LPS.rs | pub fn | (s: String) -> String {
let mut s = s.as_bytes().to_vec();
let mut d = s.clone();
d.reverse();
let mut largest_len = 0;
let mut result = String::new();
loop {
if s.len() == 0 || s.len() < largest_len {
break;
}
let (a, b) = inner_loop(&s, &d);
if a >... | longest_palindrome | identifier_name |
LPS.rs | pub fn longest_palindrome(s: String) -> String {
let mut s = s.as_bytes().to_vec();
let mut d = s.clone();
d.reverse();
let mut largest_len = 0;
let mut result = String::new();
loop {
if s.len() == 0 || s.len() < largest_len {
break;
}
let (a, b) = inner_loo... | assert_eq!("bab", longest_palindrome("babad".to_string()));
assert_eq!("bb", longest_palindrome("cbbd".to_string()));
assert_eq!("", longest_palindrome("".to_string()));
assert_eq!("bab", longest_palindrome2("babad".to_string()));
assert_eq!("bb", longest_palindrome2("cbbd".to_string()));
asser... | fn main() { | random_line_split |
mod.rs | pub mod display;
pub mod device;
pub mod state;
pub mod termios;
mod err;
use std::os::unix::io::AsRawFd;
use std::io::{self, Write};
use std::mem;
use std::fmt;
use ::libc;
use ::child::exec;
use ::pty::prelude as pty;
use self::device::Device;
use self::termios::Termios;
pub use self::state::ShellState;
pub use se... | ,
#[cfg(not(feature = "auto-resize"))]
() => {
self.state.update_from(&mut self.screen, event);
self.state
},
}
}
}
impl Iterator for Shell {
type Item = ShellState;
fn next(&mut self) -> Option<ShellState> {
match self.de... | {
self.state.update_from(&mut self.screen, event);
if let Some(size) = self.state.is_resized() {
self.set_window_size_with(&size);
}
self.state
} | conditional_block |
mod.rs | pub mod display;
pub mod device;
pub mod state;
pub mod termios;
mod err;
use std::os::unix::io::AsRawFd;
use std::io::{self, Write};
use std::mem;
use std::fmt;
use ::libc;
use ::child::exec;
use ::pty::prelude as pty;
use self::device::Device;
use self::termios::Termios;
pub use self::state::ShellState;
pub use se... | } | }
} | random_line_split |
mod.rs | pub mod display;
pub mod device;
pub mod state;
pub mod termios;
mod err;
use std::os::unix::io::AsRawFd;
use std::io::{self, Write};
use std::mem;
use std::fmt;
use ::libc;
use ::child::exec;
use ::pty::prelude as pty;
use self::device::Device;
use self::termios::Termios;
pub use self::state::ShellState;
pub use se... | (&mut self) {
if let Ok(size) = Winszed::new(libc::STDOUT_FILENO) {
self.set_window_size_with(&size);
}
}
/// The mutator method `set_window_size` redimentionnes the window
/// with a argument size.
fn set_window_size_with(&mut self, size: &Winszed) {
self.screen.set... | set_window_size | identifier_name |
mod.rs | pub mod display;
pub mod device;
pub mod state;
pub mod termios;
mod err;
use std::os::unix::io::AsRawFd;
use std::io::{self, Write};
use std::mem;
use std::fmt;
use ::libc;
use ::child::exec;
use ::pty::prelude as pty;
use self::device::Device;
use self::termios::Termios;
pub use self::state::ShellState;
pub use se... |
/// The mutator method `write` set a buffer to the display
/// without needing to print it
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.screen.write(buf)
}
/// The mutator method `next` updates the event and returns
/// the new state.
fn next(&mut self, event: state... | {
self.screen.set_window_size(size);
unsafe {
libc::ioctl(self.speudo.as_raw_fd(), libc::TIOCSWINSZ, size);
libc::kill(self.pid, libc::SIGWINCH);
}
} | identifier_body |
storage.rs | //! Abstract definition of a matrix data storage.
use std::fmt::Debug;
use std::mem;
use crate::base::allocator::{Allocator, SameShapeC, SameShapeR};
use crate::base::default_allocator::DefaultAllocator;
use crate::base::dimension::{Dim, U1};
use crate::base::Scalar;
/*
* Aliases for allocation results.
*/
/// The... |
/// Retrieves the mutable data buffer as a contiguous slice.
///
/// Matrix components may not be contiguous, depending on its strides.
fn as_mut_slice(&mut self) -> &mut [N];
}
/// A matrix storage that is stored contiguously in memory.
///
/// The storage requirement means that for any value of `i`... | {
let lid1 = self.linear_index(row_col1.0, row_col1.1);
let lid2 = self.linear_index(row_col2.0, row_col2.1);
self.swap_unchecked_linear(lid1, lid2)
} | identifier_body |
storage.rs | //! Abstract definition of a matrix data storage.
use std::fmt::Debug;
use std::mem;
use crate::base::allocator::{Allocator, SameShapeC, SameShapeR};
use crate::base::default_allocator::DefaultAllocator;
use crate::base::dimension::{Dim, U1};
use crate::base::Scalar;
/*
* Aliases for allocation results.
*/
/// The... | (&mut self, i1: usize, i2: usize) {
let a = self.get_address_unchecked_linear_mut(i1);
let b = self.get_address_unchecked_linear_mut(i2);
mem::swap(&mut *a, &mut *b);
}
/// Swaps two elements without bound-checking.
#[inline]
unsafe fn swap_unchecked(&mut self, row_col1: (usize... | swap_unchecked_linear | identifier_name |
storage.rs | //! Abstract definition of a matrix data storage.
use std::fmt::Debug;
use std::mem;
use crate::base::allocator::{Allocator, SameShapeC, SameShapeR};
use crate::base::default_allocator::DefaultAllocator;
use crate::base::dimension::{Dim, U1};
use crate::base::Scalar;
/*
* Aliases for allocation results.
*/
/// The... | /// failing to comply to this may cause Undefined Behaviors.
pub unsafe trait ContiguousStorage<N: Scalar, R: Dim, C: Dim = U1>:
Storage<N, R, C>
{
}
/// A mutable matrix storage that is stored contiguously in memory.
///
/// The storage requirement means that for any value of `i` in `[0, nrows * ncols[`, the valu... | /// `.get_unchecked_linear` returns one of the matrix component. This trait is unsafe because | random_line_split |
lib.rs | // Copyright (c) 2016-2017 Chef Software Inc. and/or applicable contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0 | // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.... | // | random_line_split |
id_type.rs | // Copyright 2015 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
// version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
// licence you accepted on initial access to the Software (the "Licences").
//
// By ... | () -> IdType {
IdType::new(&RevocationIdType::new::<MaidTypeTags>())
}
}
#[test]
fn serialisation_maid() {
use helper::*;
let obj_before = IdType::generate_random();
let mut e = cbor::Encoder::from_memory();
e.encode(&[&obj_before]).unwrap();
let mu... | generate_random | identifier_name |
id_type.rs | // Copyright 2015 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
// version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
// licence you accepted on initial access to the Software (the "Licences").
//
// By ... |
let type_tag: u64 = match String::from_utf8(tag_type_vec) {
Ok(string) => {
match string.parse::<u64>() {
Ok(type_tag) => type_tag,
Err(_) => return Err(d.error("Bad Tag Type"))
}
},
Err(_) => return E... | {
return Err(d.error("Bad IdType size"));
} | conditional_block |
id_type.rs | // Copyright 2015 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
// version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
// licence you accepted on initial access to the Software (the "Licences").
//
// By ... | //
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.
//
// Please review the Licences for the specific language governing permissions... | // bound by the terms of the MaidSafe Contributor Agreement, version 1.0. This, along with the
// Licenses can be found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR. | random_line_split |
id_type.rs | // Copyright 2015 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
// version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
// licence you accepted on initial access to the Software (the "Licences").
//
// By ... |
/// Returns the PublicKeys
pub fn public_keys(&self) -> &(crypto::sign::PublicKey, crypto::asymmetricbox::PublicKey){
&self.public_keys
}
/// Returns the PublicKeys
pub fn secret_keys(&self) -> &(crypto::sign::SecretKey, crypto::asymmetricbox::SecretKey) {
&self.secret_keys
}
... | {
let combined_iter = (&self.public_keys.0).0.into_iter().chain((&self.public_keys.1).0.into_iter());
let mut combined: Vec<u8> = Vec::new();
for iter in combined_iter {
combined.push(*iter);
}
for i in self.type_tag.to_string().into_bytes().into_iter() {
... | identifier_body |
schema2.rs | use types::{ColumnType};
pub trait Schema {
fn len(&self) -> usize;
fn name(&self, index: usize) -> &str;
fn ctype(&self, index: usize) -> ColumnType;
fn nullable(&self, index: usize) -> bool; | pub names: Vec<String>,
pub types: Vec<ColumnType>,
pub nullable: Vec<bool>,
}
impl Schema2 {
pub fn new() -> Self {
Schema2 {
names: Vec::new(),
types: Vec::new(),
nullable: Vec::new(),
}
}
pub fn add(&mut self,
name: &str,
... | }
#[derive(Clone)]
pub struct Schema2 { | random_line_split |
schema2.rs | use types::{ColumnType};
pub trait Schema {
fn len(&self) -> usize;
fn name(&self, index: usize) -> &str;
fn ctype(&self, index: usize) -> ColumnType;
fn nullable(&self, index: usize) -> bool;
}
#[derive(Clone)]
pub struct | {
pub names: Vec<String>,
pub types: Vec<ColumnType>,
pub nullable: Vec<bool>,
}
impl Schema2 {
pub fn new() -> Self {
Schema2 {
names: Vec::new(),
types: Vec::new(),
nullable: Vec::new(),
}
}
pub fn add(&mut self,
name: &str,... | Schema2 | identifier_name |
schema2.rs | use types::{ColumnType};
pub trait Schema {
fn len(&self) -> usize;
fn name(&self, index: usize) -> &str;
fn ctype(&self, index: usize) -> ColumnType;
fn nullable(&self, index: usize) -> bool;
}
#[derive(Clone)]
pub struct Schema2 {
pub names: Vec<String>,
pub types: Vec<ColumnType>,
pub n... |
pub fn set_nullable(&mut self, index: usize, nullability: bool) {
self.nullable[index] = nullability;
}
}
impl Schema for Schema2 {
fn len(&self) -> usize {
self.names.len()
}
fn name(&self, index: usize) -> &str {
self.names[index].as_str()
}
fn ctype(&self, ind... | {
self.names.push(name.to_string());
self.types.push(ctype);
self.nullable.push(nullable);
} | identifier_body |
lib.rs | // Copyright 2021 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 ... | (il: bool) -> &'static str {
if il {
"32-bit instruction trapped"
} else {
"16-bit instruction trapped"
}
}
/// Parses a decimal or hexadecimal number from a string.
///
/// If the string starts with `"0x"` then it will be parsed as hexadecimal, otherwise it will be
/// assumed to be decima... | describe_il | identifier_name |
lib.rs | // Copyright 2021 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 ... |
fn check_res0(self) -> Result<Self, DecodeError> {
if self.value!= 0 {
Err(DecodeError::InvalidRes0 { res0: self.value })
} else {
Ok(self)
}
}
/// Returns the value as a hexadecimal string, or "true" or "false" if it is a single bit.
pub fn value_strin... | {
let description = describer(self.value)?.to_string();
Ok(self.with_description(description))
} | identifier_body |
lib.rs | // Copyright 2021 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 ... | ),
0b111100 => (
"BRK instruction execution in AArch64 state",
decode_iss_breakpoint(iss.value)?,
None,
),
_ => return Err(DecodeError::InvalidEc { ec: ec.value }),
};
let iss = FieldInfo {
description: iss_description,
subfield... | None, | random_line_split |
mod.rs | // Copyright 2017 The Xyrosource Team.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except acco... | () -> slog::Logger {
let drain = slog_term::streamer().compact().build().fuse();
Logger::root(drain, o!("version" => VERSION))
}
| setup | identifier_name |
mod.rs | // Copyright 2017 The Xyrosource Team.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except acco... |
pub fn setup() -> slog::Logger {
let drain = slog_term::streamer().compact().build().fuse();
Logger::root(drain, o!("version" => VERSION))
} | use self::version::VERSION; | random_line_split |
mod.rs | // Copyright 2017 The Xyrosource Team.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except acco... | {
let drain = slog_term::streamer().compact().build().fuse();
Logger::root(drain, o!("version" => VERSION))
} | identifier_body | |
rate_limit.rs | // Copyright 2016 The Grin Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agree... |
/// Get a mutable reference to the inner sink.
pub fn get_mut(&mut self) -> &mut R {
&mut self.reader
}
/// Consumes this combinator, returning the underlying sink.
///
/// Note that this may discard intermediate state of this combinator, so
/// care should be taken to avoid losing resources when this is ca... | {
&self.reader
} | identifier_body |
rate_limit.rs | // Copyright 2016 The Grin Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agree... | (&mut self, buf: &mut [u8]) -> io::Result<usize> {
// Check passed Time
let time_passed = self.last_check.elapsed();
self.last_check = Instant::now();
self.allowed += time_passed.as_secs() as usize * self.max as usize;
// Throttle
if self.allowed > self.max as usize {
self.allowed = self.max as usize;
... | read | identifier_name |
rate_limit.rs | // Copyright 2016 The Grin Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agree... | assert_eq!(cursor.position(), 8);
}
#[test]
fn should_throttle_read() {
let buf = vec![1; 64];
let mut t_buf = ThrottledReader::new(Cursor::new(buf), 8);
let mut dst = Cursor::new(vec![0; 64]);
for _ in 0..16 {
let _ = t_buf.read_buf(&mut dst);
}
assert_eq!(dst.position(), 8);
}
} | let _ = t_buf.write_buf(&mut Cursor::new(vec![1; 8]));
}
let cursor = t_buf.into_inner(); | random_line_split |
rate_limit.rs | // Copyright 2016 The Grin Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agree... |
res
}
fn flush(&mut self) -> io::Result<()> {
self.writer.flush()
}
}
impl<T: AsyncWrite> AsyncWrite for ThrottledWriter<T> {
fn shutdown(&mut self) -> Poll<(), io::Error> {
self.writer.shutdown()
}
}
#[cfg(test)]
mod test {
use super::*;
use std::io::Cursor;
#[test]
fn should_throttle_write() {
l... | {
self.allowed -= n;
} | conditional_block |
markdown.rs | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | {text}
<script type="text/javascript">
window.playgroundUrl = "{playground}";
</script>
{after_content}
</body>
</html>"#,
title = Escape(title),
css = css,
in_header = external_html.in_header,
before_content = external_html.before_content,
text = rendered... | <![endif]-->
{before_content}
<h1 class="title">{title}</h1> | random_line_split |
markdown.rs | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | (input: &str, mut output: Path, matches: &getopts::Matches,
external_html: &ExternalHtml, include_toc: bool) -> int {
let input_p = Path::new(input);
output.push(input_p.filestem().unwrap());
output.set_extension("html");
let mut css = String::new();
for name in matches.opt_strs("mark... | render | identifier_name |
markdown.rs | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... |
/// Render `input` (e.g. "foo.md") into an HTML file in `output`
/// (e.g. output = "bar" => "bar/foo.html").
pub fn render(input: &str, mut output: Path, matches: &getopts::Matches,
external_html: &ExternalHtml, include_toc: bool) -> int {
let input_p = Path::new(input);
output.push(input_p.fil... | {
let mut metadata = Vec::new();
for line in s.lines() {
if line.starts_with("%") {
// remove %<whitespace>
metadata.push(line.slice_from(1).trim_left())
} else {
let line_start_byte = s.subslice_offset(line);
return (metadata, s.slice_from(line_st... | identifier_body |
markdown.rs | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... |
Ok(f) => f
};
let (metadata, text) = extract_leading_metadata(input_str.as_slice());
if metadata.len() == 0 {
let _ = writeln!(&mut io::stderr(),
"invalid markdown file: expecting initial line with `%...TITLE...`");
return 5;
}
let title = metadata[... | {
let _ = writeln!(&mut io::stderr(),
"error opening `{}` for writing: {}",
output.display(), e);
return 4;
} | conditional_block |
mod.rs | pub mod default;
pub mod plugged;
| #[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
pub enum Tag {
Encrypted(Vec<u8>, Vec<u8>),
PlainText(Vec<u8>, String)
}
#[derive(Debug)]
pub enum TagName {
OfEncrypted(Vec<u8>),
OfPlain(Vec<u8>),
}
#[derive(Clone, Debug)]
pub struct StorageRecord {
pub id: Vec<u8>,
pub value: Option<E... | use errors::prelude::*;
use services::wallet::language;
use services::wallet::wallet::EncryptedValue;
| random_line_split |
mod.rs | pub mod default;
pub mod plugged;
use errors::prelude::*;
use services::wallet::language;
use services::wallet::wallet::EncryptedValue;
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
pub enum | {
Encrypted(Vec<u8>, Vec<u8>),
PlainText(Vec<u8>, String)
}
#[derive(Debug)]
pub enum TagName {
OfEncrypted(Vec<u8>),
OfPlain(Vec<u8>),
}
#[derive(Clone, Debug)]
pub struct StorageRecord {
pub id: Vec<u8>,
pub value: Option<EncryptedValue>,
pub type_: Option<Vec<u8>>,
pub tags: Option... | Tag | identifier_name |
drop-env.rs | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | (&mut self) {
A.fetch_add(1, Ordering::SeqCst);
}
}
fn main() {
t1();
t2();
t3();
}
fn t1() {
let b = B;
let mut foo = || {
yield;
drop(b);
};
let n = A.load(Ordering::SeqCst);
drop(unsafe { foo.resume() });
assert_eq!(A.load(Ordering::SeqCst), n);
... | drop | identifier_name |
drop-env.rs | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | impl Drop for B {
fn drop(&mut self) {
A.fetch_add(1, Ordering::SeqCst);
}
}
fn main() {
t1();
t2();
t3();
}
fn t1() {
let b = B;
let mut foo = || {
yield;
drop(b);
};
let n = A.load(Ordering::SeqCst);
drop(unsafe { foo.resume() });
assert_eq!(A.loa... | struct B;
| random_line_split |
drop-env.rs | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... |
fn t2() {
let b = B;
let mut foo = || {
yield b;
};
let n = A.load(Ordering::SeqCst);
drop(unsafe { foo.resume() });
assert_eq!(A.load(Ordering::SeqCst), n + 1);
drop(foo);
assert_eq!(A.load(Ordering::SeqCst), n + 1);
}
fn t3() {
let b = B;
let foo = || {
yiel... | {
let b = B;
let mut foo = || {
yield;
drop(b);
};
let n = A.load(Ordering::SeqCst);
drop(unsafe { foo.resume() });
assert_eq!(A.load(Ordering::SeqCst), n);
drop(foo);
assert_eq!(A.load(Ordering::SeqCst), n + 1);
} | identifier_body |
local_data.rs | r a derived/new value)
// back with replace(v). We take special care to reuse the allocation in this
// case for performance reasons.
//
// However, that does mean that if a value is replaced with None, the
// allocation will stay alive and the entry will stay in the TLD map until the
// task deallocates. This makes th... |
fn le(&self, other: &Ref<T>) -> bool { (**self).le(&**other) }
fn gt(&self, other: &Ref<T>) -> bool { (**self).gt(&**other) }
fn ge(&self, other: &Ref<T>) -> bool { (**self).ge(&**other) }
}
impl<T: cmp::Ord +'static> cmp::Ord for Ref<T> {
fn cmp(&self, other: &Ref<T>) -> cmp::Ordering {
(**se... | { (**self).lt(&**other) } | identifier_body |
local_data.rs | (or a derived/new value)
// back with replace(v). We take special care to reuse the allocation in this
// case for performance reasons.
//
// However, that does mean that if a value is replaced with None, the
// allocation will stay alive and the entry will stay in the TLD map until the
// task deallocates. This makes... | TLDValue {
box_ptr: box_ptr,
drop_fn: d::<T>
}
}
}
impl Drop for TLDValue {
fn drop(&mut self) {
// box_ptr should always be non-null. Check it anyway just to be thorough
if!self.box_ptr.is_null() {
unsafe { (self.drop_fn)(self.box_ptr) }
... | // the contained value is valid; drop it
ptr::read(&(*value_box).value);
}
// the box will be deallocated by the guard
} | random_line_split |
local_data.rs | or a derived/new value)
// back with replace(v). We take special care to reuse the allocation in this
// case for performance reasons.
//
// However, that does mean that if a value is replaced with None, the
// allocation will stay alive and the entry will stay in the TLD map until the
// task deallocates. This makes t... | () {
static MY_KEY: Key<String> = &KeyValueKey;
MY_KEY.replace(Some("first data".to_string()));
MY_KEY.replace(Some("next data".to_string())); // Shouldn't leak.
assert!(MY_KEY.get().unwrap().as_slice() == "next data");
}
#[test]
fn test_tls_pop() {
static MY_KEY: Ke... | test_tls_overwrite | identifier_name |
failure.rs | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | line: uint) ->!;
}
let (file, line) = *file_line;
unsafe { begin_unwind(fmt, file, line) }
} | #[allow(ctypes)]
extern {
#[lang = "begin_unwind"]
fn begin_unwind(fmt: &fmt::Arguments, file: &'static str, | random_line_split |
failure.rs | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | (expr_file_line: &(&'static str, &'static str, uint)) ->! {
let (expr, file, line) = *expr_file_line;
let ref file_line = (file, line);
format_args!(|args| -> () {
begin_unwind(args, file_line);
}, "{}", expr);
unsafe { intrinsics::abort() }
}
#[cold] #[inline(never)]
#[lang="fail_bounds_c... | fail_ | identifier_name |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.