Skip to content

Instantly share code, notes, and snippets.

View durka's full-sized avatar

Alex Burka durka

View GitHub Profile
$ RUST_BACKTRACE=1 cargo script --debug -D quote -e 'extern crate proc_macro; proc_macro::TokenStream::from(quote!(1 + 1))'
Updating registry `https://github.com/rust-lang/crates.io-index`
Compiling expr v0.1.0 (file:///Users/alex/.cargo/script-cache/expr-c9c44fbc071235a7)
Finished dev [unoptimized + debuginfo] target(s) in 3.97 secs
thread 'main' panicked at 'proc_macro::__internal::with_sess() called before set_parse_sess()!', libproc_macro/lib.rs:898:9
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
1: std::sys_common::backtrace::print
2: std::panicking::default_hook::{{closure}}
3: std::panicking::default_hook
$ RUST_BACKTRACE=1 cargo script -e 'std::thread::spawn(|| { panic!("foo"); }).join().unwrap();'
thread '<unnamed>' panicked at 'foo', expr.rs:18:36
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
1: std::sys_common::backtrace::print
2: std::panicking::default_hook::{{closure}}
3: std::panicking::default_hook
4: std::panicking::rust_panic_with_hook
5: std::panicking::begin_panic
File "main.py", line 99, in train
err = 100-100.*correct/total
RuntimeError: value cannot be converted to type uint8_t without overflow: 256
$ cargo script -e '#[derive(Copy)] struct S(std::marker::PhantomData<*const T>);'
Compiling expr v0.1.0 (file:///Users/alex/.cargo/script-cache/expr-0658c6978a7ee620)
error[E0412]: cannot find type `T` in this scope
--> expr.rs:18:69
|
18 | match {#[derive(Copy)] struct S(std::marker::PhantomData<*const T>);} {
| ^ did you mean `S`?
error[E0204]: the trait `Copy` may not be implemented for this type
--> expr.rs:18:21
error[E0658]: use of unstable library feature 'inclusive_range_fields' (see issue #49022)
--> /Users/alex/.cargo/git/checkouts/math_traits-377ef1ba09fb5bd4/915b114/src/cast.rs:29:29
|
29 | if v >= r.start && v <= r.end {
| ^^^^^^^
...
226 | / impl_cast_unchecked!(
227 | | u8 as [ u8, i16, u16, i32, u32, i64, u64, i128, u128, f32, f64, usize, isize],
228 | | u16 as [ u16, i32, u32, i64, u64, i128, u128, f32, f64, usize, isize],
229 | | u32 as [ u32, u64, i128, u128, f32, f64 ],
$ cargo script -D subprocess -e 'subprocess::Exec::cmd("rg").args(&["x", "not_exist.rs"]).stdout(subprocess::Redirection::Pipe).stderr(subprocess::Redirection::Merge).capture()?.stdout_str()'
"not_exist.rs: No such file or directory (os error 2)\nNo files were searched, which means ripgrep probably applied a filter you didn\'t expect. Try running again with --debug.\n"
foo:
3x 3: 0 (0%)
4x 3: 0 (0%)
6x 4: 0 (0%)
4x 4: 0 (0%)
bar:
3 x3 : 0 (0%)
4 x3 : 0 (0%)
6 x4 : 0 (0%)
4 x4 : 0 (0%)
@durka
durka / v2.rs
Last active March 14, 2018 03:49
// `parts` is an Iterator<Item=&str>
// `conv_mod` returns a `Result<Vec<String>, _>`
let themod = if parts.peek().is_some() {
if !parts.peek().unwrap().starts_with("Key") {
Some(conv_mod(parts.next().unwrap())?)
} else {
None
}
} else {
HTTP/1.1 200 OK
Content-Type: application/x-tar
Content-Length: 184155181
Connection: keep-alive
Date: Tue, 06 Mar 2018 16:57:33 GMT
Last-Modified: Thu, 01 Mar 2018 23:57:34 GMT
ETag: "46084fdedf9d05aab76dddb912b671ae-22"
x-amz-version-id: 47ev.5AQrLClfVnV_kbE9BgkB.ZKfvMV
Accept-Ranges: bytes
Server: AmazonS3
@durka
durka / playground.rs
Created February 21, 2018 23:39 — forked from anonymous/playground.rs
How to get around lockstep iteration restrictions
#![feature(trace_macros)] trace_macros!(true);
macro_rules! doc_items {
(@distribute $docs:tt $($item:item)*) => {
$(doc_items!(@output $docs $item);)*
};
(@output [$($doc:expr),*] $item:item) => {
$(#[doc=$doc])*
$item
};