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
set_watch_mode.rs
use std::io; use super::super::{WriteTo, WatchMode, WatchModeReader, WriteResult, Reader, ReaderStatus, MessageInner, Message}; #[derive(Debug, Eq, PartialEq, Clone)] pub struct SetWatchMode { mode: WatchMode, } #[derive(Debug)] pub struct SetWatchModeReader { inner: WatchModeReader, } impl SetWatchMode { pub fn new(mode: WatchMode) -> Self { SetWatchMode { mode } } pub fn mode(&self) -> WatchMode { self.mode } pub fn reader() -> SetWatchModeReader { SetWatchModeReader { inner: WatchMode::reader() } } } impl MessageInner for SetWatchMode { #[inline] fn wrap(self) -> Message { Message::SetWatchMode(self) } } impl Reader<SetWatchMode> for SetWatchModeReader { fn resume<R>(&mut self, input: &mut R) -> io::Result<ReaderStatus<SetWatchMode>> where R: io::Read { let status = self.inner.resume(input)?; Ok(status.map(|mode| SetWatchMode::new(mode))) } fn rewind(&mut self) { self.inner.rewind(); } } impl WriteTo for SetWatchMode { fn write_to<W: io::Write>(&self, target: &mut W) -> WriteResult { self.mode.write_to(target) } } #[cfg(test)] mod test { use super::*; use super::super::super::{MessageType, WatchMode}; #[test] fn test_reader_with_tagged() { let input = vec![ /* type */ MessageType::SetWatchMode.into(), /* mode = tagged */ 2, /* tag */ 0, 0, 0, 0, 0, 0, 255, 255 ]; test_reader! { Message::reader(), input, ReaderStatus::Pending, ReaderStatus::Pending, ReaderStatus::Pending, ReaderStatus::Complete(Message::SetWatchMode(SetWatchMode::new(WatchMode::Tagged(65535)))) }; } #[test] fn test_reader() { let input = vec![ /* type */ MessageType::SetWatchMode.into(), /* mode = all */ 1 ]; test_reader! { Message::reader(), input,
ReaderStatus::Pending, ReaderStatus::Complete(Message::SetWatchMode(SetWatchMode::new(WatchMode::All))) }; } }
ReaderStatus::Pending,
random_line_split
rayon.rs
use crate::{ProgressBar, ProgressBarIter}; use rayon::iter::{ plumbing::{Consumer, Folder, Producer, ProducerCallback, UnindexedConsumer}, IndexedParallelIterator, ParallelIterator, }; use std::convert::TryFrom; /// Wraps a Rayon parallel iterator. /// /// See [`ProgressIterator`](trait.ProgressIterator.html) for method /// documentation. pub trait ParallelProgressIterator where Self: Sized + ParallelIterator, { /// Wrap an iterator with a custom progress bar. fn progress_with(self, progress: ProgressBar) -> ProgressBarIter<Self>; /// Wrap an iterator with an explicit element count. fn progress_count(self, len: u64) -> ProgressBarIter<Self> { self.progress_with(ProgressBar::new(len)) } fn progress(self) -> ProgressBarIter<Self> where Self: IndexedParallelIterator, { let len = u64::try_from(self.len()).unwrap(); self.progress_count(len) } /// Wrap an iterator with a progress bar and style it. fn progress_with_style(self, style: crate::ProgressStyle) -> ProgressBarIter<Self> where Self: IndexedParallelIterator, { let len = u64::try_from(self.len()).unwrap(); let bar = ProgressBar::new(len).with_style(style); self.progress_with(bar) } } impl<S: Send, T: ParallelIterator<Item = S>> ParallelProgressIterator for T { fn progress_with(self, progress: ProgressBar) -> ProgressBarIter<Self> { ProgressBarIter { it: self, progress } } } impl<S: Send, T: IndexedParallelIterator<Item = S>> IndexedParallelIterator for ProgressBarIter<T> { fn len(&self) -> usize
fn drive<C: Consumer<Self::Item>>(self, consumer: C) -> <C as Consumer<Self::Item>>::Result { let consumer = ProgressConsumer::new(consumer, self.progress); self.it.drive(consumer) } fn with_producer<CB: ProducerCallback<Self::Item>>( self, callback: CB, ) -> <CB as ProducerCallback<Self::Item>>::Output { return self.it.with_producer(Callback { callback, progress: self.progress, }); struct Callback<CB> { callback: CB, progress: ProgressBar, } impl<T, CB: ProducerCallback<T>> ProducerCallback<T> for Callback<CB> { type Output = CB::Output; fn callback<P>(self, base: P) -> CB::Output where P: Producer<Item = T>, { let producer = ProgressProducer { base, progress: self.progress, }; self.callback.callback(producer) } } } } struct ProgressProducer<T> { base: T, progress: ProgressBar, } impl<T, P: Producer<Item = T>> Producer for ProgressProducer<P> { type Item = T; type IntoIter = ProgressBarIter<P::IntoIter>; fn into_iter(self) -> Self::IntoIter { ProgressBarIter { it: self.base.into_iter(), progress: self.progress, } } fn min_len(&self) -> usize { self.base.min_len() } fn max_len(&self) -> usize { self.base.max_len() } fn split_at(self, index: usize) -> (Self, Self) { let (left, right) = self.base.split_at(index); ( ProgressProducer { base: left, progress: self.progress.clone(), }, ProgressProducer { base: right, progress: self.progress, }, ) } } struct ProgressConsumer<C> { base: C, progress: ProgressBar, } impl<C> ProgressConsumer<C> { fn new(base: C, progress: ProgressBar) -> Self { ProgressConsumer { base, progress } } } impl<T, C: Consumer<T>> Consumer<T> for ProgressConsumer<C> { type Folder = ProgressFolder<C::Folder>; type Reducer = C::Reducer; type Result = C::Result; fn split_at(self, index: usize) -> (Self, Self, Self::Reducer) { let (left, right, reducer) = self.base.split_at(index); ( ProgressConsumer::new(left, self.progress.clone()), ProgressConsumer::new(right, self.progress), reducer, ) } fn into_folder(self) -> Self::Folder { ProgressFolder { base: self.base.into_folder(), progress: self.progress, } } fn full(&self) -> bool { self.base.full() } } impl<T, C: UnindexedConsumer<T>> UnindexedConsumer<T> for ProgressConsumer<C> { fn split_off_left(&self) -> Self { ProgressConsumer::new(self.base.split_off_left(), self.progress.clone()) } fn to_reducer(&self) -> Self::Reducer { self.base.to_reducer() } } struct ProgressFolder<C> { base: C, progress: ProgressBar, } impl<T, C: Folder<T>> Folder<T> for ProgressFolder<C> { type Result = C::Result; fn consume(self, item: T) -> Self { self.progress.inc(1); ProgressFolder { base: self.base.consume(item), progress: self.progress, } } fn complete(self) -> C::Result { self.base.complete() } fn full(&self) -> bool { self.base.full() } } impl<S: Send, T: ParallelIterator<Item = S>> ParallelIterator for ProgressBarIter<T> { type Item = S; fn drive_unindexed<C: UnindexedConsumer<Self::Item>>(self, consumer: C) -> C::Result { let consumer1 = ProgressConsumer::new(consumer, self.progress.clone()); self.it.drive_unindexed(consumer1) } } #[cfg(test)] mod test { use crate::ProgressStyle; use crate::{ParallelProgressIterator, ProgressBar, ProgressBarIter}; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; #[test] fn it_can_wrap_a_parallel_iterator() { let v = vec![1, 2, 3]; fn wrap<'a, T: ParallelIterator<Item = &'a i32>>(it: ProgressBarIter<T>) { assert_eq!(it.map(|x| x * 2).collect::<Vec<_>>(), vec![2, 4, 6]); } wrap(v.par_iter().progress_count(3)); wrap({ let pb = ProgressBar::new(v.len() as u64); v.par_iter().progress_with(pb) }); wrap({ let style = ProgressStyle::default_bar().template("{wide_bar:.red} {percent}/100%"); v.par_iter().progress_with_style(style) }); } }
{ self.it.len() }
identifier_body
rayon.rs
use crate::{ProgressBar, ProgressBarIter}; use rayon::iter::{ plumbing::{Consumer, Folder, Producer, ProducerCallback, UnindexedConsumer}, IndexedParallelIterator, ParallelIterator, }; use std::convert::TryFrom; /// Wraps a Rayon parallel iterator. /// /// See [`ProgressIterator`](trait.ProgressIterator.html) for method /// documentation. pub trait ParallelProgressIterator where Self: Sized + ParallelIterator, { /// Wrap an iterator with a custom progress bar. fn progress_with(self, progress: ProgressBar) -> ProgressBarIter<Self>; /// Wrap an iterator with an explicit element count. fn progress_count(self, len: u64) -> ProgressBarIter<Self> { self.progress_with(ProgressBar::new(len)) } fn progress(self) -> ProgressBarIter<Self> where Self: IndexedParallelIterator, { let len = u64::try_from(self.len()).unwrap(); self.progress_count(len) } /// Wrap an iterator with a progress bar and style it. fn progress_with_style(self, style: crate::ProgressStyle) -> ProgressBarIter<Self> where Self: IndexedParallelIterator, { let len = u64::try_from(self.len()).unwrap(); let bar = ProgressBar::new(len).with_style(style); self.progress_with(bar) } } impl<S: Send, T: ParallelIterator<Item = S>> ParallelProgressIterator for T { fn progress_with(self, progress: ProgressBar) -> ProgressBarIter<Self> { ProgressBarIter { it: self, progress } } } impl<S: Send, T: IndexedParallelIterator<Item = S>> IndexedParallelIterator for ProgressBarIter<T> { fn len(&self) -> usize { self.it.len() } fn drive<C: Consumer<Self::Item>>(self, consumer: C) -> <C as Consumer<Self::Item>>::Result { let consumer = ProgressConsumer::new(consumer, self.progress); self.it.drive(consumer) } fn with_producer<CB: ProducerCallback<Self::Item>>( self, callback: CB, ) -> <CB as ProducerCallback<Self::Item>>::Output { return self.it.with_producer(Callback { callback, progress: self.progress, }); struct Callback<CB> { callback: CB, progress: ProgressBar, } impl<T, CB: ProducerCallback<T>> ProducerCallback<T> for Callback<CB> { type Output = CB::Output; fn callback<P>(self, base: P) -> CB::Output where P: Producer<Item = T>, { let producer = ProgressProducer { base, progress: self.progress, }; self.callback.callback(producer) } } } } struct ProgressProducer<T> { base: T, progress: ProgressBar, } impl<T, P: Producer<Item = T>> Producer for ProgressProducer<P> { type Item = T; type IntoIter = ProgressBarIter<P::IntoIter>; fn into_iter(self) -> Self::IntoIter { ProgressBarIter { it: self.base.into_iter(), progress: self.progress, } } fn min_len(&self) -> usize { self.base.min_len() } fn max_len(&self) -> usize { self.base.max_len() } fn split_at(self, index: usize) -> (Self, Self) { let (left, right) = self.base.split_at(index); ( ProgressProducer { base: left, progress: self.progress.clone(), }, ProgressProducer { base: right, progress: self.progress, }, ) } } struct ProgressConsumer<C> { base: C, progress: ProgressBar, } impl<C> ProgressConsumer<C> { fn new(base: C, progress: ProgressBar) -> Self { ProgressConsumer { base, progress } } } impl<T, C: Consumer<T>> Consumer<T> for ProgressConsumer<C> { type Folder = ProgressFolder<C::Folder>; type Reducer = C::Reducer; type Result = C::Result; fn split_at(self, index: usize) -> (Self, Self, Self::Reducer) { let (left, right, reducer) = self.base.split_at(index); ( ProgressConsumer::new(left, self.progress.clone()), ProgressConsumer::new(right, self.progress), reducer, ) } fn into_folder(self) -> Self::Folder { ProgressFolder { base: self.base.into_folder(), progress: self.progress, } } fn full(&self) -> bool { self.base.full() } } impl<T, C: UnindexedConsumer<T>> UnindexedConsumer<T> for ProgressConsumer<C> { fn split_off_left(&self) -> Self { ProgressConsumer::new(self.base.split_off_left(), self.progress.clone()) } fn to_reducer(&self) -> Self::Reducer { self.base.to_reducer() } } struct ProgressFolder<C> { base: C, progress: ProgressBar, } impl<T, C: Folder<T>> Folder<T> for ProgressFolder<C> { type Result = C::Result; fn
(self, item: T) -> Self { self.progress.inc(1); ProgressFolder { base: self.base.consume(item), progress: self.progress, } } fn complete(self) -> C::Result { self.base.complete() } fn full(&self) -> bool { self.base.full() } } impl<S: Send, T: ParallelIterator<Item = S>> ParallelIterator for ProgressBarIter<T> { type Item = S; fn drive_unindexed<C: UnindexedConsumer<Self::Item>>(self, consumer: C) -> C::Result { let consumer1 = ProgressConsumer::new(consumer, self.progress.clone()); self.it.drive_unindexed(consumer1) } } #[cfg(test)] mod test { use crate::ProgressStyle; use crate::{ParallelProgressIterator, ProgressBar, ProgressBarIter}; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; #[test] fn it_can_wrap_a_parallel_iterator() { let v = vec![1, 2, 3]; fn wrap<'a, T: ParallelIterator<Item = &'a i32>>(it: ProgressBarIter<T>) { assert_eq!(it.map(|x| x * 2).collect::<Vec<_>>(), vec![2, 4, 6]); } wrap(v.par_iter().progress_count(3)); wrap({ let pb = ProgressBar::new(v.len() as u64); v.par_iter().progress_with(pb) }); wrap({ let style = ProgressStyle::default_bar().template("{wide_bar:.red} {percent}/100%"); v.par_iter().progress_with_style(style) }); } }
consume
identifier_name
rayon.rs
use crate::{ProgressBar, ProgressBarIter}; use rayon::iter::{ plumbing::{Consumer, Folder, Producer, ProducerCallback, UnindexedConsumer}, IndexedParallelIterator, ParallelIterator, }; use std::convert::TryFrom; /// Wraps a Rayon parallel iterator. /// /// See [`ProgressIterator`](trait.ProgressIterator.html) for method /// documentation. pub trait ParallelProgressIterator where Self: Sized + ParallelIterator, { /// Wrap an iterator with a custom progress bar. fn progress_with(self, progress: ProgressBar) -> ProgressBarIter<Self>; /// Wrap an iterator with an explicit element count. fn progress_count(self, len: u64) -> ProgressBarIter<Self> { self.progress_with(ProgressBar::new(len)) } fn progress(self) -> ProgressBarIter<Self> where Self: IndexedParallelIterator, { let len = u64::try_from(self.len()).unwrap(); self.progress_count(len) } /// Wrap an iterator with a progress bar and style it. fn progress_with_style(self, style: crate::ProgressStyle) -> ProgressBarIter<Self> where Self: IndexedParallelIterator, { let len = u64::try_from(self.len()).unwrap(); let bar = ProgressBar::new(len).with_style(style); self.progress_with(bar) } } impl<S: Send, T: ParallelIterator<Item = S>> ParallelProgressIterator for T { fn progress_with(self, progress: ProgressBar) -> ProgressBarIter<Self> { ProgressBarIter { it: self, progress } } } impl<S: Send, T: IndexedParallelIterator<Item = S>> IndexedParallelIterator for ProgressBarIter<T> { fn len(&self) -> usize { self.it.len() } fn drive<C: Consumer<Self::Item>>(self, consumer: C) -> <C as Consumer<Self::Item>>::Result { let consumer = ProgressConsumer::new(consumer, self.progress); self.it.drive(consumer) } fn with_producer<CB: ProducerCallback<Self::Item>>( self, callback: CB, ) -> <CB as ProducerCallback<Self::Item>>::Output { return self.it.with_producer(Callback { callback, progress: self.progress, }); struct Callback<CB> { callback: CB, progress: ProgressBar, } impl<T, CB: ProducerCallback<T>> ProducerCallback<T> for Callback<CB> { type Output = CB::Output; fn callback<P>(self, base: P) -> CB::Output where P: Producer<Item = T>, { let producer = ProgressProducer { base, progress: self.progress, }; self.callback.callback(producer) } } } } struct ProgressProducer<T> { base: T, progress: ProgressBar, } impl<T, P: Producer<Item = T>> Producer for ProgressProducer<P> { type Item = T; type IntoIter = ProgressBarIter<P::IntoIter>; fn into_iter(self) -> Self::IntoIter { ProgressBarIter { it: self.base.into_iter(), progress: self.progress, } } fn min_len(&self) -> usize { self.base.min_len() } fn max_len(&self) -> usize { self.base.max_len() } fn split_at(self, index: usize) -> (Self, Self) { let (left, right) = self.base.split_at(index); ( ProgressProducer { base: left, progress: self.progress.clone(), }, ProgressProducer { base: right, progress: self.progress, }, ) } } struct ProgressConsumer<C> { base: C, progress: ProgressBar, } impl<C> ProgressConsumer<C> {
} impl<T, C: Consumer<T>> Consumer<T> for ProgressConsumer<C> { type Folder = ProgressFolder<C::Folder>; type Reducer = C::Reducer; type Result = C::Result; fn split_at(self, index: usize) -> (Self, Self, Self::Reducer) { let (left, right, reducer) = self.base.split_at(index); ( ProgressConsumer::new(left, self.progress.clone()), ProgressConsumer::new(right, self.progress), reducer, ) } fn into_folder(self) -> Self::Folder { ProgressFolder { base: self.base.into_folder(), progress: self.progress, } } fn full(&self) -> bool { self.base.full() } } impl<T, C: UnindexedConsumer<T>> UnindexedConsumer<T> for ProgressConsumer<C> { fn split_off_left(&self) -> Self { ProgressConsumer::new(self.base.split_off_left(), self.progress.clone()) } fn to_reducer(&self) -> Self::Reducer { self.base.to_reducer() } } struct ProgressFolder<C> { base: C, progress: ProgressBar, } impl<T, C: Folder<T>> Folder<T> for ProgressFolder<C> { type Result = C::Result; fn consume(self, item: T) -> Self { self.progress.inc(1); ProgressFolder { base: self.base.consume(item), progress: self.progress, } } fn complete(self) -> C::Result { self.base.complete() } fn full(&self) -> bool { self.base.full() } } impl<S: Send, T: ParallelIterator<Item = S>> ParallelIterator for ProgressBarIter<T> { type Item = S; fn drive_unindexed<C: UnindexedConsumer<Self::Item>>(self, consumer: C) -> C::Result { let consumer1 = ProgressConsumer::new(consumer, self.progress.clone()); self.it.drive_unindexed(consumer1) } } #[cfg(test)] mod test { use crate::ProgressStyle; use crate::{ParallelProgressIterator, ProgressBar, ProgressBarIter}; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; #[test] fn it_can_wrap_a_parallel_iterator() { let v = vec![1, 2, 3]; fn wrap<'a, T: ParallelIterator<Item = &'a i32>>(it: ProgressBarIter<T>) { assert_eq!(it.map(|x| x * 2).collect::<Vec<_>>(), vec![2, 4, 6]); } wrap(v.par_iter().progress_count(3)); wrap({ let pb = ProgressBar::new(v.len() as u64); v.par_iter().progress_with(pb) }); wrap({ let style = ProgressStyle::default_bar().template("{wide_bar:.red} {percent}/100%"); v.par_iter().progress_with_style(style) }); } }
fn new(base: C, progress: ProgressBar) -> Self { ProgressConsumer { base, progress } }
random_line_split
issue-17441.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 http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. fn
() { let _foo = &[1_usize, 2] as [usize]; //~^ ERROR cast to unsized type: `&[usize; 2]` as `[usize]` //~^^ HELP consider using an implicit coercion to `&[usize]` instead // FIXME (#22405): Replace `Box::new` with `box` here when/if possible. let _bar = Box::new(1_usize) as std::fmt::Debug; //~^ ERROR cast to unsized type: `Box<usize>` as `core::fmt::Debug` //~^^ HELP did you mean `Box<core::fmt::Debug>`? let _baz = 1_usize as std::fmt::Debug; //~^ ERROR cast to unsized type: `usize` as `core::fmt::Debug` //~^^ HELP consider using a box or reference as appropriate let _quux = [1_usize, 2] as [usize]; //~^ ERROR cast to unsized type: `[usize; 2]` as `[usize]` //~^^ HELP consider using a box or reference as appropriate }
main
identifier_name
issue-17441.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 http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. fn main()
{ let _foo = &[1_usize, 2] as [usize]; //~^ ERROR cast to unsized type: `&[usize; 2]` as `[usize]` //~^^ HELP consider using an implicit coercion to `&[usize]` instead // FIXME (#22405): Replace `Box::new` with `box` here when/if possible. let _bar = Box::new(1_usize) as std::fmt::Debug; //~^ ERROR cast to unsized type: `Box<usize>` as `core::fmt::Debug` //~^^ HELP did you mean `Box<core::fmt::Debug>`? let _baz = 1_usize as std::fmt::Debug; //~^ ERROR cast to unsized type: `usize` as `core::fmt::Debug` //~^^ HELP consider using a box or reference as appropriate let _quux = [1_usize, 2] as [usize]; //~^ ERROR cast to unsized type: `[usize; 2]` as `[usize]` //~^^ HELP consider using a box or reference as appropriate }
identifier_body
issue-17441.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. //
fn main() { let _foo = &[1_usize, 2] as [usize]; //~^ ERROR cast to unsized type: `&[usize; 2]` as `[usize]` //~^^ HELP consider using an implicit coercion to `&[usize]` instead // FIXME (#22405): Replace `Box::new` with `box` here when/if possible. let _bar = Box::new(1_usize) as std::fmt::Debug; //~^ ERROR cast to unsized type: `Box<usize>` as `core::fmt::Debug` //~^^ HELP did you mean `Box<core::fmt::Debug>`? let _baz = 1_usize as std::fmt::Debug; //~^ ERROR cast to unsized type: `usize` as `core::fmt::Debug` //~^^ HELP consider using a box or reference as appropriate let _quux = [1_usize, 2] as [usize]; //~^ ERROR cast to unsized type: `[usize; 2]` as `[usize]` //~^^ HELP consider using a box or reference as appropriate }
// 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 according to those terms.
random_line_split
mod.rs
use lexer::dfa::*; use lexer::re::Test; use rust::RustWrite; use std::io::{self, Write}; #[cfg(test)] mod test; /// Generates a fn `__tokenize` based on the given DFA with the following signature: /// /// ```ignore /// fn tokenize(text: &str) -> Option<(usize, usize)> /// ``` /// /// This function returns `None` if there is no matching /// token. Otherwise, it returns the pair of (NFA index, length) for /// the next token. pub fn compile_tokenize_fn<W: Write>( prefix: &str, dfa: &DFA, out: &mut RustWrite<W>) -> io::Result<()> { let mut matcher = Matcher { prefix: prefix, dfa: dfa, out: out }; try!(matcher.tokenize()); Ok(()) } struct Matcher<'m, W: Write+'m> { prefix: &'m str, dfa: &'m DFA, out: &'m mut RustWrite<W>, } impl<'m,W> Matcher<'m,W> where W: Write { fn tokenize(&mut self) -> io::Result<()> { rust!(self.out, "fn {}tokenize(text: &str) -> Option<(usize, usize)> {{", self.prefix); rust!(self.out, "let mut {}chars = text.char_indices();", self.prefix); rust!(self.out, "let mut {}current_match: Option<(usize, usize)> = None;", self.prefix); rust!(self.out, "let mut {}current_state: usize = 0;", self.prefix); rust!(self.out, "loop {{"); rust!(self.out, "match {}current_state {{", self.prefix); for (index, state) in self.dfa.states.iter().enumerate() { rust!(self.out, "{} => {{", index); try!(self.state(state)); rust!(self.out, "}}"); } rust!(self.out, "_ => {{ panic!(\"invalid state {{}}\", {}current_state); }}", self.prefix); rust!(self.out, "}}"); rust!(self.out, "}}"); rust!(self.out, "}}"); Ok(()) } fn state(&mut self, state: &State) -> io::Result<()> { // this could be pulled to the top of the loop, but we want to // encourage LLVM to convert the loop+switch pair into actual // gotos. rust!(self.out, "let ({}index, {}ch) = \ match {}chars.next() {{ Some(p) => p, None => return {}current_match }};", self.prefix, self.prefix, self.prefix, self.prefix); rust!(self.out, "match {}ch {{", self.prefix); for &(test, target_state) in &state.test_edges { match test { Test::Char(ch) => { rust!(self.out, "{:?} => {{", ch); let index = format!("{}index + {}", self.prefix, ch.len_utf8()); try!(self.transition(target_state, &index)); rust!(self.out, "}}"); } } } rust!(self.out, "_ => {{"); let index = format!("{}index + {}ch.len_utf8()", self.prefix, self.prefix); try!(self.transition(state.other_edge, &index)); rust!(self.out, "}}"); rust!(self.out, "}}"); Ok(()) } fn
(&mut self, target_state: DFAStateIndex, index: &str) -> io::Result<()> { match self.dfa.state(target_state).kind { Kind::Accepts(nfa) => { rust!(self.out, "{}current_match = Some(({}, {}));", self.prefix, nfa.index(), index) } Kind::Neither => { } Kind::Reject => { rust!(self.out, "return {}current_match;", self.prefix); return Ok(()); } } rust!(self.out, "{}current_state = {};", self.prefix, target_state.index()); rust!(self.out, "continue;"); Ok(()) } }
transition
identifier_name
mod.rs
use lexer::dfa::*; use lexer::re::Test; use rust::RustWrite; use std::io::{self, Write}; #[cfg(test)] mod test; /// Generates a fn `__tokenize` based on the given DFA with the following signature: /// /// ```ignore /// fn tokenize(text: &str) -> Option<(usize, usize)> /// ``` /// /// This function returns `None` if there is no matching /// token. Otherwise, it returns the pair of (NFA index, length) for /// the next token. pub fn compile_tokenize_fn<W: Write>( prefix: &str, dfa: &DFA, out: &mut RustWrite<W>) -> io::Result<()>
struct Matcher<'m, W: Write+'m> { prefix: &'m str, dfa: &'m DFA, out: &'m mut RustWrite<W>, } impl<'m,W> Matcher<'m,W> where W: Write { fn tokenize(&mut self) -> io::Result<()> { rust!(self.out, "fn {}tokenize(text: &str) -> Option<(usize, usize)> {{", self.prefix); rust!(self.out, "let mut {}chars = text.char_indices();", self.prefix); rust!(self.out, "let mut {}current_match: Option<(usize, usize)> = None;", self.prefix); rust!(self.out, "let mut {}current_state: usize = 0;", self.prefix); rust!(self.out, "loop {{"); rust!(self.out, "match {}current_state {{", self.prefix); for (index, state) in self.dfa.states.iter().enumerate() { rust!(self.out, "{} => {{", index); try!(self.state(state)); rust!(self.out, "}}"); } rust!(self.out, "_ => {{ panic!(\"invalid state {{}}\", {}current_state); }}", self.prefix); rust!(self.out, "}}"); rust!(self.out, "}}"); rust!(self.out, "}}"); Ok(()) } fn state(&mut self, state: &State) -> io::Result<()> { // this could be pulled to the top of the loop, but we want to // encourage LLVM to convert the loop+switch pair into actual // gotos. rust!(self.out, "let ({}index, {}ch) = \ match {}chars.next() {{ Some(p) => p, None => return {}current_match }};", self.prefix, self.prefix, self.prefix, self.prefix); rust!(self.out, "match {}ch {{", self.prefix); for &(test, target_state) in &state.test_edges { match test { Test::Char(ch) => { rust!(self.out, "{:?} => {{", ch); let index = format!("{}index + {}", self.prefix, ch.len_utf8()); try!(self.transition(target_state, &index)); rust!(self.out, "}}"); } } } rust!(self.out, "_ => {{"); let index = format!("{}index + {}ch.len_utf8()", self.prefix, self.prefix); try!(self.transition(state.other_edge, &index)); rust!(self.out, "}}"); rust!(self.out, "}}"); Ok(()) } fn transition(&mut self, target_state: DFAStateIndex, index: &str) -> io::Result<()> { match self.dfa.state(target_state).kind { Kind::Accepts(nfa) => { rust!(self.out, "{}current_match = Some(({}, {}));", self.prefix, nfa.index(), index) } Kind::Neither => { } Kind::Reject => { rust!(self.out, "return {}current_match;", self.prefix); return Ok(()); } } rust!(self.out, "{}current_state = {};", self.prefix, target_state.index()); rust!(self.out, "continue;"); Ok(()) } }
{ let mut matcher = Matcher { prefix: prefix, dfa: dfa, out: out }; try!(matcher.tokenize()); Ok(()) }
identifier_body
mod.rs
use lexer::dfa::*; use lexer::re::Test; use rust::RustWrite; use std::io::{self, Write}; #[cfg(test)] mod test; /// Generates a fn `__tokenize` based on the given DFA with the following signature: /// /// ```ignore /// fn tokenize(text: &str) -> Option<(usize, usize)> /// ``` /// /// This function returns `None` if there is no matching /// token. Otherwise, it returns the pair of (NFA index, length) for /// the next token. pub fn compile_tokenize_fn<W: Write>( prefix: &str, dfa: &DFA, out: &mut RustWrite<W>) -> io::Result<()> { let mut matcher = Matcher { prefix: prefix, dfa: dfa, out: out }; try!(matcher.tokenize()); Ok(()) } struct Matcher<'m, W: Write+'m> { prefix: &'m str, dfa: &'m DFA, out: &'m mut RustWrite<W>, } impl<'m,W> Matcher<'m,W> where W: Write { fn tokenize(&mut self) -> io::Result<()> { rust!(self.out, "fn {}tokenize(text: &str) -> Option<(usize, usize)> {{", self.prefix); rust!(self.out, "let mut {}chars = text.char_indices();", self.prefix); rust!(self.out, "let mut {}current_match: Option<(usize, usize)> = None;", self.prefix); rust!(self.out, "let mut {}current_state: usize = 0;", self.prefix); rust!(self.out, "loop {{"); rust!(self.out, "match {}current_state {{", self.prefix); for (index, state) in self.dfa.states.iter().enumerate() { rust!(self.out, "{} => {{", index); try!(self.state(state)); rust!(self.out, "}}"); } rust!(self.out, "_ => {{ panic!(\"invalid state {{}}\", {}current_state); }}", self.prefix); rust!(self.out, "}}"); rust!(self.out, "}}"); rust!(self.out, "}}"); Ok(()) } fn state(&mut self, state: &State) -> io::Result<()> { // this could be pulled to the top of the loop, but we want to // encourage LLVM to convert the loop+switch pair into actual // gotos. rust!(self.out, "let ({}index, {}ch) = \ match {}chars.next() {{ Some(p) => p, None => return {}current_match }};", self.prefix, self.prefix, self.prefix, self.prefix); rust!(self.out, "match {}ch {{", self.prefix); for &(test, target_state) in &state.test_edges { match test { Test::Char(ch) => { rust!(self.out, "{:?} => {{", ch); let index = format!("{}index + {}", self.prefix, ch.len_utf8()); try!(self.transition(target_state, &index)); rust!(self.out, "}}"); } } } rust!(self.out, "_ => {{"); let index = format!("{}index + {}ch.len_utf8()", self.prefix, self.prefix); try!(self.transition(state.other_edge, &index)); rust!(self.out, "}}"); rust!(self.out, "}}"); Ok(()) } fn transition(&mut self, target_state: DFAStateIndex, index: &str) -> io::Result<()> { match self.dfa.state(target_state).kind { Kind::Accepts(nfa) => { rust!(self.out, "{}current_match = Some(({}, {}));", self.prefix, nfa.index(), index) } Kind::Neither =>
Kind::Reject => { rust!(self.out, "return {}current_match;", self.prefix); return Ok(()); } } rust!(self.out, "{}current_state = {};", self.prefix, target_state.index()); rust!(self.out, "continue;"); Ok(()) } }
{ }
conditional_block
mod.rs
use lexer::dfa::*; use lexer::re::Test; use rust::RustWrite; use std::io::{self, Write}; #[cfg(test)] mod test; /// Generates a fn `__tokenize` based on the given DFA with the following signature: /// /// ```ignore /// fn tokenize(text: &str) -> Option<(usize, usize)> /// ``` /// /// This function returns `None` if there is no matching /// token. Otherwise, it returns the pair of (NFA index, length) for /// the next token. pub fn compile_tokenize_fn<W: Write>( prefix: &str, dfa: &DFA, out: &mut RustWrite<W>) -> io::Result<()> { let mut matcher = Matcher { prefix: prefix, dfa: dfa, out: out }; try!(matcher.tokenize()); Ok(()) } struct Matcher<'m, W: Write+'m> { prefix: &'m str, dfa: &'m DFA, out: &'m mut RustWrite<W>, } impl<'m,W> Matcher<'m,W> where W: Write { fn tokenize(&mut self) -> io::Result<()> { rust!(self.out, "fn {}tokenize(text: &str) -> Option<(usize, usize)> {{", self.prefix); rust!(self.out, "let mut {}chars = text.char_indices();", self.prefix); rust!(self.out, "let mut {}current_match: Option<(usize, usize)> = None;", self.prefix); rust!(self.out, "let mut {}current_state: usize = 0;", self.prefix); rust!(self.out, "loop {{"); rust!(self.out, "match {}current_state {{", self.prefix);
for (index, state) in self.dfa.states.iter().enumerate() { rust!(self.out, "{} => {{", index); try!(self.state(state)); rust!(self.out, "}}"); } rust!(self.out, "_ => {{ panic!(\"invalid state {{}}\", {}current_state); }}", self.prefix); rust!(self.out, "}}"); rust!(self.out, "}}"); rust!(self.out, "}}"); Ok(()) } fn state(&mut self, state: &State) -> io::Result<()> { // this could be pulled to the top of the loop, but we want to // encourage LLVM to convert the loop+switch pair into actual // gotos. rust!(self.out, "let ({}index, {}ch) = \ match {}chars.next() {{ Some(p) => p, None => return {}current_match }};", self.prefix, self.prefix, self.prefix, self.prefix); rust!(self.out, "match {}ch {{", self.prefix); for &(test, target_state) in &state.test_edges { match test { Test::Char(ch) => { rust!(self.out, "{:?} => {{", ch); let index = format!("{}index + {}", self.prefix, ch.len_utf8()); try!(self.transition(target_state, &index)); rust!(self.out, "}}"); } } } rust!(self.out, "_ => {{"); let index = format!("{}index + {}ch.len_utf8()", self.prefix, self.prefix); try!(self.transition(state.other_edge, &index)); rust!(self.out, "}}"); rust!(self.out, "}}"); Ok(()) } fn transition(&mut self, target_state: DFAStateIndex, index: &str) -> io::Result<()> { match self.dfa.state(target_state).kind { Kind::Accepts(nfa) => { rust!(self.out, "{}current_match = Some(({}, {}));", self.prefix, nfa.index(), index) } Kind::Neither => { } Kind::Reject => { rust!(self.out, "return {}current_match;", self.prefix); return Ok(()); } } rust!(self.out, "{}current_state = {};", self.prefix, target_state.index()); rust!(self.out, "continue;"); Ok(()) } }
random_line_split
channel_list.rs
use ui::ncurses::*; use ui::{RIGHT_PANEL_WIDTH, CMD_ENTRY_HEIGHT, STATS_PANEL_HEIGHT, Position, Size}; use ui::window::BorderWindow; pub struct ChannelList { window: BorderWindow, channels: Vec<String>, } impl ChannelList { pub fn new(size: Size) -> ChannelList { let window = BorderWindow::new( Position::new(size.width - RIGHT_PANEL_WIDTH, 0), Size::new(RIGHT_PANEL_WIDTH, size.height - STATS_PANEL_HEIGHT - CMD_ENTRY_HEIGHT), Size::new(1, 1)); ChannelList { window: window, channels: Vec::new(), } } fn display_channel(&self, index: i32, name: &str) { mvwaddstr(self.window.inner.id, index, 1, &format!("{} - {}", index + 1, name)); wrefresh(self.window.inner.id); } pub fn add_channel(&mut self, name: &str) { self.channels.push(name.to_string()); self.display_channel(self.channels.len() as i32 - 1, name); } pub fn remove_channel(&mut self, name: &str) -> bool { let index = self.channels.iter().position(|ref s| s.as_str() == name); match index { Some(index) => { self.channels.remove(index); // TODO: Separate this redraw code into its own function once this method is actually used wclear(self.window.inner.id); for (index, channel) in self.channels.iter().by_ref().enumerate() { self.display_channel(index as i32, &channel); } true
}, None => false, } } }
random_line_split
channel_list.rs
use ui::ncurses::*; use ui::{RIGHT_PANEL_WIDTH, CMD_ENTRY_HEIGHT, STATS_PANEL_HEIGHT, Position, Size}; use ui::window::BorderWindow; pub struct ChannelList { window: BorderWindow, channels: Vec<String>, } impl ChannelList { pub fn new(size: Size) -> ChannelList { let window = BorderWindow::new( Position::new(size.width - RIGHT_PANEL_WIDTH, 0), Size::new(RIGHT_PANEL_WIDTH, size.height - STATS_PANEL_HEIGHT - CMD_ENTRY_HEIGHT), Size::new(1, 1)); ChannelList { window: window, channels: Vec::new(), } } fn display_channel(&self, index: i32, name: &str)
pub fn add_channel(&mut self, name: &str) { self.channels.push(name.to_string()); self.display_channel(self.channels.len() as i32 - 1, name); } pub fn remove_channel(&mut self, name: &str) -> bool { let index = self.channels.iter().position(|ref s| s.as_str() == name); match index { Some(index) => { self.channels.remove(index); // TODO: Separate this redraw code into its own function once this method is actually used wclear(self.window.inner.id); for (index, channel) in self.channels.iter().by_ref().enumerate() { self.display_channel(index as i32, &channel); } true }, None => false, } } }
{ mvwaddstr(self.window.inner.id, index, 1, &format!("{} - {}", index + 1, name)); wrefresh(self.window.inner.id); }
identifier_body
channel_list.rs
use ui::ncurses::*; use ui::{RIGHT_PANEL_WIDTH, CMD_ENTRY_HEIGHT, STATS_PANEL_HEIGHT, Position, Size}; use ui::window::BorderWindow; pub struct ChannelList { window: BorderWindow, channels: Vec<String>, } impl ChannelList { pub fn new(size: Size) -> ChannelList { let window = BorderWindow::new( Position::new(size.width - RIGHT_PANEL_WIDTH, 0), Size::new(RIGHT_PANEL_WIDTH, size.height - STATS_PANEL_HEIGHT - CMD_ENTRY_HEIGHT), Size::new(1, 1)); ChannelList { window: window, channels: Vec::new(), } } fn display_channel(&self, index: i32, name: &str) { mvwaddstr(self.window.inner.id, index, 1, &format!("{} - {}", index + 1, name)); wrefresh(self.window.inner.id); } pub fn add_channel(&mut self, name: &str) { self.channels.push(name.to_string()); self.display_channel(self.channels.len() as i32 - 1, name); } pub fn
(&mut self, name: &str) -> bool { let index = self.channels.iter().position(|ref s| s.as_str() == name); match index { Some(index) => { self.channels.remove(index); // TODO: Separate this redraw code into its own function once this method is actually used wclear(self.window.inner.id); for (index, channel) in self.channels.iter().by_ref().enumerate() { self.display_channel(index as i32, &channel); } true }, None => false, } } }
remove_channel
identifier_name
validitystate.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 dom::bindings::codegen::Bindings::ValidityStateBinding; use dom::bindings::codegen::Bindings::ValidityStateBinding::ValidityStateMethods; use dom::bindings::js::{JS, Root}; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::element::Element; use dom::window::Window; // https://html.spec.whatwg.org/multipage/#validity-states #[derive(JSTraceable)] #[derive(HeapSizeOf)] pub enum ValidityStatus { ValueMissing, TypeMismatch, PatternMismatch, TooLong, TooShort, RangeUnderflow, RangeOverflow, StepMismatch, BadInput, CustomError, Valid } bitflags!{ pub flags ValidationFlags: u32 { const VALUE_MISSING = 0b0000000001, const TYPE_MISMATCH = 0b0000000010, const PATTERN_MISMATCH = 0b0000000100, const TOO_LONG = 0b0000001000, const TOO_SHORT = 0b0000010000, const RANGE_UNDERFLOW = 0b0000100000, const RANGE_OVERFLOW = 0b0001000000, const STEP_MISMATCH = 0b0010000000, const BAD_INPUT = 0b0100000000, const CUSTOM_ERROR = 0b1000000000, } } // https://html.spec.whatwg.org/multipage/#validitystate #[dom_struct] pub struct ValidityState { reflector_: Reflector, element: JS<Element>, state: ValidityStatus }
state: ValidityStatus::Valid } } pub fn new(window: &Window, element: &Element) -> Root<ValidityState> { reflect_dom_object(box ValidityState::new_inherited(element), window, ValidityStateBinding::Wrap) } } impl ValidityStateMethods for ValidityState { // https://html.spec.whatwg.org/multipage/#dom-validitystate-valuemissing fn ValueMissing(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-typemismatch fn TypeMismatch(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-patternmismatch fn PatternMismatch(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-toolong fn TooLong(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-tooshort fn TooShort(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-rangeunderflow fn RangeUnderflow(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-rangeoverflow fn RangeOverflow(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-stepmismatch fn StepMismatch(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-badinput fn BadInput(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-customerror fn CustomError(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-valid fn Valid(&self) -> bool { false } }
impl ValidityState { fn new_inherited(element: &Element) -> ValidityState { ValidityState { reflector_: Reflector::new(), element: JS::from_ref(element),
random_line_split
validitystate.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 dom::bindings::codegen::Bindings::ValidityStateBinding; use dom::bindings::codegen::Bindings::ValidityStateBinding::ValidityStateMethods; use dom::bindings::js::{JS, Root}; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::element::Element; use dom::window::Window; // https://html.spec.whatwg.org/multipage/#validity-states #[derive(JSTraceable)] #[derive(HeapSizeOf)] pub enum ValidityStatus { ValueMissing, TypeMismatch, PatternMismatch, TooLong, TooShort, RangeUnderflow, RangeOverflow, StepMismatch, BadInput, CustomError, Valid } bitflags!{ pub flags ValidationFlags: u32 { const VALUE_MISSING = 0b0000000001, const TYPE_MISMATCH = 0b0000000010, const PATTERN_MISMATCH = 0b0000000100, const TOO_LONG = 0b0000001000, const TOO_SHORT = 0b0000010000, const RANGE_UNDERFLOW = 0b0000100000, const RANGE_OVERFLOW = 0b0001000000, const STEP_MISMATCH = 0b0010000000, const BAD_INPUT = 0b0100000000, const CUSTOM_ERROR = 0b1000000000, } } // https://html.spec.whatwg.org/multipage/#validitystate #[dom_struct] pub struct ValidityState { reflector_: Reflector, element: JS<Element>, state: ValidityStatus } impl ValidityState { fn new_inherited(element: &Element) -> ValidityState { ValidityState { reflector_: Reflector::new(), element: JS::from_ref(element), state: ValidityStatus::Valid } } pub fn new(window: &Window, element: &Element) -> Root<ValidityState> { reflect_dom_object(box ValidityState::new_inherited(element), window, ValidityStateBinding::Wrap) } } impl ValidityStateMethods for ValidityState { // https://html.spec.whatwg.org/multipage/#dom-validitystate-valuemissing fn ValueMissing(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-typemismatch fn TypeMismatch(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-patternmismatch fn PatternMismatch(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-toolong fn TooLong(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-tooshort fn TooShort(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-rangeunderflow fn RangeUnderflow(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-rangeoverflow fn RangeOverflow(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-stepmismatch fn StepMismatch(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-badinput fn BadInput(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-customerror fn CustomError(&self) -> bool
// https://html.spec.whatwg.org/multipage/#dom-validitystate-valid fn Valid(&self) -> bool { false } }
{ false }
identifier_body
validitystate.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 dom::bindings::codegen::Bindings::ValidityStateBinding; use dom::bindings::codegen::Bindings::ValidityStateBinding::ValidityStateMethods; use dom::bindings::js::{JS, Root}; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::element::Element; use dom::window::Window; // https://html.spec.whatwg.org/multipage/#validity-states #[derive(JSTraceable)] #[derive(HeapSizeOf)] pub enum ValidityStatus { ValueMissing, TypeMismatch, PatternMismatch, TooLong, TooShort, RangeUnderflow, RangeOverflow, StepMismatch, BadInput, CustomError, Valid } bitflags!{ pub flags ValidationFlags: u32 { const VALUE_MISSING = 0b0000000001, const TYPE_MISMATCH = 0b0000000010, const PATTERN_MISMATCH = 0b0000000100, const TOO_LONG = 0b0000001000, const TOO_SHORT = 0b0000010000, const RANGE_UNDERFLOW = 0b0000100000, const RANGE_OVERFLOW = 0b0001000000, const STEP_MISMATCH = 0b0010000000, const BAD_INPUT = 0b0100000000, const CUSTOM_ERROR = 0b1000000000, } } // https://html.spec.whatwg.org/multipage/#validitystate #[dom_struct] pub struct ValidityState { reflector_: Reflector, element: JS<Element>, state: ValidityStatus } impl ValidityState { fn new_inherited(element: &Element) -> ValidityState { ValidityState { reflector_: Reflector::new(), element: JS::from_ref(element), state: ValidityStatus::Valid } } pub fn new(window: &Window, element: &Element) -> Root<ValidityState> { reflect_dom_object(box ValidityState::new_inherited(element), window, ValidityStateBinding::Wrap) } } impl ValidityStateMethods for ValidityState { // https://html.spec.whatwg.org/multipage/#dom-validitystate-valuemissing fn
(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-typemismatch fn TypeMismatch(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-patternmismatch fn PatternMismatch(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-toolong fn TooLong(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-tooshort fn TooShort(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-rangeunderflow fn RangeUnderflow(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-rangeoverflow fn RangeOverflow(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-stepmismatch fn StepMismatch(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-badinput fn BadInput(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-customerror fn CustomError(&self) -> bool { false } // https://html.spec.whatwg.org/multipage/#dom-validitystate-valid fn Valid(&self) -> bool { false } }
ValueMissing
identifier_name
udt.rs
extern crate cassandra; use cassandra::*; fn main() { let mut cluster = Cluster::new(); cluster.set_contact_points("127.0.0.1").unwrap(); match cluster.connect() { Ok(ref mut session) => { let schema = session.get_schema(); session.execute( "CREATE KEYSPACE examples WITH replication = \ { 'class': 'SimpleStrategy','replication_factor': '3' }", 0 ); session.execute( "CREATE TYPE examples.phone_numbers (phone1 int, phone2 int)", 0 ); session.execute( "CREATE TYPE examples.address \ (street text, city text, zip int, phone set<frozen<phone_numbers>>)" ,0 ); session.execute( "CREATE TABLE examples.udt (id timeuuid, address frozen<address>, PRIMARY KEY(id))", 0 ); insert_into_udt(&session, schema).unwrap(); select_from_udt(&session).unwrap(); session.close().wait().unwrap(); } err => println!("{:?}", err), } } fn select_from_udt(session: &Session) -> Result<(), CassandraError> { let query = "SELECT * FROM examples.udt"; let statement = Statement::new(query, 0); let mut future = session.execute_statement(&statement); match future.wait() { Err(err) => panic!("Error: {:?}", err), Ok(result) => { for row in result.iter() { let id_value = row.get_column_by_name("id"); let address_value = row.get_column_by_name("address"); let fields_iter = try!(address_value.use_type_iter()); let id_str = try!(id_value.get_uuid()).to_string(); println!("id {}", id_str);
match field.1.get_type() { ValueType::VARCHAR => println!("{}", try!(field.1.get_string())), ValueType::INT => println!("{}", try!(field.1.get_int32())), ValueType::SET => for phone_numbers in try!(field.1.as_set_iterator()) { for phone_number in try!(phone_numbers.as_user_type_iterator()) { let phone_number_value = phone_number.1; println!("{}", phone_number_value); } }, other => panic!("Unsupported type: {:?}", other), } } } Ok(()) } } } fn insert_into_udt(session: &Session) -> Result<(), CassandraError> { let query = "INSERT INTO examples.udt (id, address) VALUES (?,?)"; let mut statement = Statement::new(query, 2); let uuid_gen = UuidGen::new(); let udt_address = schema.get_udt("examples", "address"); let udt_phone = cass_keyspace_meta_user_type_by_name(&schema, "examples", "phone_numbers"); let id = uuid_gen.get_time(); let id_str = id.to_string(); let mut address = UserType::new(udt_address); let mut phone = Set::new(2); let mut phone_numbers = UserType::new(udt_phone); phone_numbers.set_int32_by_name("phone1", 0 + 1).unwrap(); phone_numbers.set_int32_by_name("phone2", 0 + 2).unwrap(); phone.append_user_type(phone_numbers).unwrap(); address.set_string_by_name("street", &id_str).unwrap(); address.set_int32_by_name("zip", id.0.time_and_version as i32).unwrap(); address.set_collection_by_name("phone", phone).unwrap(); statement.bind(0, id).unwrap(); statement.bind_user_type(1, address).unwrap(); let mut future = session.execute_statement(&statement); match future.wait() { Ok(_) => Ok(()), Err(err) => panic!("Error: {:?}", err), } }
for field in fields_iter { println!("{}", field.0);
random_line_split
udt.rs
extern crate cassandra; use cassandra::*; fn main()
"CREATE TYPE examples.address \ (street text, city text, zip int, phone set<frozen<phone_numbers>>)" ,0 ); session.execute( "CREATE TABLE examples.udt (id timeuuid, address frozen<address>, PRIMARY KEY(id))", 0 ); insert_into_udt(&session, schema).unwrap(); select_from_udt(&session).unwrap(); session.close().wait().unwrap(); } err => println!("{:?}", err), } } fn select_from_udt(session: &Session) -> Result<(), CassandraError> { let query = "SELECT * FROM examples.udt"; let statement = Statement::new(query, 0); let mut future = session.execute_statement(&statement); match future.wait() { Err(err) => panic!("Error: {:?}", err), Ok(result) => { for row in result.iter() { let id_value = row.get_column_by_name("id"); let address_value = row.get_column_by_name("address"); let fields_iter = try!(address_value.use_type_iter()); let id_str = try!(id_value.get_uuid()).to_string(); println!("id {}", id_str); for field in fields_iter { println!("{}", field.0); match field.1.get_type() { ValueType::VARCHAR => println!("{}", try!(field.1.get_string())), ValueType::INT => println!("{}", try!(field.1.get_int32())), ValueType::SET => for phone_numbers in try!(field.1.as_set_iterator()) { for phone_number in try!(phone_numbers.as_user_type_iterator()) { let phone_number_value = phone_number.1; println!("{}", phone_number_value); } }, other => panic!("Unsupported type: {:?}", other), } } } Ok(()) } } } fn insert_into_udt(session: &Session) -> Result<(), CassandraError> { let query = "INSERT INTO examples.udt (id, address) VALUES (?,?)"; let mut statement = Statement::new(query, 2); let uuid_gen = UuidGen::new(); let udt_address = schema.get_udt("examples", "address"); let udt_phone = cass_keyspace_meta_user_type_by_name(&schema, "examples", "phone_numbers"); let id = uuid_gen.get_time(); let id_str = id.to_string(); let mut address = UserType::new(udt_address); let mut phone = Set::new(2); let mut phone_numbers = UserType::new(udt_phone); phone_numbers.set_int32_by_name("phone1", 0 + 1).unwrap(); phone_numbers.set_int32_by_name("phone2", 0 + 2).unwrap(); phone.append_user_type(phone_numbers).unwrap(); address.set_string_by_name("street", &id_str).unwrap(); address.set_int32_by_name("zip", id.0.time_and_version as i32).unwrap(); address.set_collection_by_name("phone", phone).unwrap(); statement.bind(0, id).unwrap(); statement.bind_user_type(1, address).unwrap(); let mut future = session.execute_statement(&statement); match future.wait() { Ok(_) => Ok(()), Err(err) => panic!("Error: {:?}", err), } }
{ let mut cluster = Cluster::new(); cluster.set_contact_points("127.0.0.1").unwrap(); match cluster.connect() { Ok(ref mut session) => { let schema = session.get_schema(); session.execute( "CREATE KEYSPACE examples WITH replication = \ { 'class': 'SimpleStrategy', 'replication_factor': '3' }", 0 ); session.execute( "CREATE TYPE examples.phone_numbers (phone1 int, phone2 int)", 0 ); session.execute(
identifier_body
udt.rs
extern crate cassandra; use cassandra::*; fn main() { let mut cluster = Cluster::new(); cluster.set_contact_points("127.0.0.1").unwrap(); match cluster.connect() { Ok(ref mut session) => { let schema = session.get_schema(); session.execute( "CREATE KEYSPACE examples WITH replication = \ { 'class': 'SimpleStrategy','replication_factor': '3' }", 0 ); session.execute( "CREATE TYPE examples.phone_numbers (phone1 int, phone2 int)", 0 ); session.execute( "CREATE TYPE examples.address \ (street text, city text, zip int, phone set<frozen<phone_numbers>>)" ,0 ); session.execute( "CREATE TABLE examples.udt (id timeuuid, address frozen<address>, PRIMARY KEY(id))", 0 ); insert_into_udt(&session, schema).unwrap(); select_from_udt(&session).unwrap(); session.close().wait().unwrap(); } err => println!("{:?}", err), } } fn select_from_udt(session: &Session) -> Result<(), CassandraError> { let query = "SELECT * FROM examples.udt"; let statement = Statement::new(query, 0); let mut future = session.execute_statement(&statement); match future.wait() { Err(err) => panic!("Error: {:?}", err), Ok(result) => { for row in result.iter() { let id_value = row.get_column_by_name("id"); let address_value = row.get_column_by_name("address"); let fields_iter = try!(address_value.use_type_iter()); let id_str = try!(id_value.get_uuid()).to_string(); println!("id {}", id_str); for field in fields_iter { println!("{}", field.0); match field.1.get_type() { ValueType::VARCHAR => println!("{}", try!(field.1.get_string())), ValueType::INT => println!("{}", try!(field.1.get_int32())), ValueType::SET => for phone_numbers in try!(field.1.as_set_iterator()) { for phone_number in try!(phone_numbers.as_user_type_iterator()) { let phone_number_value = phone_number.1; println!("{}", phone_number_value); } }, other => panic!("Unsupported type: {:?}", other), } } } Ok(()) } } } fn
(session: &Session) -> Result<(), CassandraError> { let query = "INSERT INTO examples.udt (id, address) VALUES (?,?)"; let mut statement = Statement::new(query, 2); let uuid_gen = UuidGen::new(); let udt_address = schema.get_udt("examples", "address"); let udt_phone = cass_keyspace_meta_user_type_by_name(&schema, "examples", "phone_numbers"); let id = uuid_gen.get_time(); let id_str = id.to_string(); let mut address = UserType::new(udt_address); let mut phone = Set::new(2); let mut phone_numbers = UserType::new(udt_phone); phone_numbers.set_int32_by_name("phone1", 0 + 1).unwrap(); phone_numbers.set_int32_by_name("phone2", 0 + 2).unwrap(); phone.append_user_type(phone_numbers).unwrap(); address.set_string_by_name("street", &id_str).unwrap(); address.set_int32_by_name("zip", id.0.time_and_version as i32).unwrap(); address.set_collection_by_name("phone", phone).unwrap(); statement.bind(0, id).unwrap(); statement.bind_user_type(1, address).unwrap(); let mut future = session.execute_statement(&statement); match future.wait() { Ok(_) => Ok(()), Err(err) => panic!("Error: {:?}", err), } }
insert_into_udt
identifier_name