-
remexre
If I want to state that a type should be a unit struct using trait bounds, would Copy + Default be reasonable?
-
sleffy
remexre, why a unit struct?
-
stephaneyfx
Soni: Do you want to allow other crates to implement RawCommand for their own types?
-
remexre
sleffy: So it can be optimized out, but I have a type to use for type-level programming
-
sleffy
remexre, I don't think there's any good way to do that tbh. If this was Haskell I'd say give it a function to any `T`, like, absurd style, but that doesn't work so much here. You could throw in some asserts in places that `size_of` is zero alongside those trait bounds?
-
Soni
stephaneyfx: I am ok with that, yes
-
Arnavion
remexre: diesel uses tests with size_of to assert that its types are zero-sized. There's no way to force them to be that at compile-time unfortunately
-
stephaneyfx
Soni: Ok, so what I was going to suggest does not apply then, sorry :p
-
glandium
what's the state of the art for lexers in rust?
-
Soni
stephaneyfx: mainly I want other crates to be able to use it and read the docs for it, I just don't mind them being able to implement it because I'm not gonna accept their types anyway
-
Soni
(I have a separate function for each valid type)
-
stephaneyfx
Soni: I was going to suggest you could get rid of the Unsafe* trait and do something like this to define RawCommand and prevent other types from implementing it:
docs.rs/ndarray/0.11.1/ndarray/trait.Dimension.html (look at PrivateMarker). But I understand it's not really what you're after.
-
Soni
stephaneyfx: return mem::zeroed() ?
-
stephaneyfx
Soni: It won't work because you won't be able to even write the signature of the method:
play.rust-lang.org/?gist=ab705d18b0…9d7a762f25973b1ea481&version=stable
-
Soni
hmm *wonders if there's a way around that*
-
Soni
I'd like to believe rust has associated types for fns so you can write something like AType::fun::Return
-
danieldg
Soni: the Fn trait has that, but not in general
-
Soni
can you exploit any of those traits to get an Private?
-
danieldg
I didn't read your entire problem, but probably not the way you want to
-
nox
Soni: No.
-
Soni
ok :(
-
LambdaComplex
Any chance that Luminarys on github uses this network? Got some questions about Synapse
-
snowe_
can someone explain why lazy_static! changes the type of the variable?
paste.rs/2iL
-
danieldg
snowe_: you're trying to move the object out of the static there
-
danieldg
have new accept a reference instead
-
snowe_
danieldg: oh.
-
snowe_
it's a library
-
snowe_
and I was following the example
-
durka42
where'd you find the example?
-
snowe_
-
danieldg
that would work if the type were Copy
-
durka42
if the type were copy you could write *COMMAND_BUS yeah
-
snowe_
I did copy and paste the code to rename the types, but I don't really understand how it works.
-
durka42
well you'll notice they never try to use the static by value there
-
durka42
it's always either calling a method or &*
-
theobromine
what prevents us from doing rust development on iphones, ipads, etc?
-
theobromine
and by that i mean compiled on the device itself
-
durka42
what lazy_static actually does behind the scenes is create a new type whose name is your static, and make it deref to the value that you set
-
durka42
so that might make the error message more understandable
-
snowe_
oh. ok yeah that does. thanks durka42
-
danieldg
theobromine: apple doesn't let you compile code on the device iirc (to include any kind if JIT)
-
danieldg
s/if/of/
-
snowe_
so if I didn't want to have a static EventBus, then how could I change the code to accept a non-static &self?
-
snowe_
referring to this line here.
-
snowe_
-
durka42
hmm, what happens if you just remove the 'static
-
durka42
oh, it won't work because it's also 'static on line 45
-
durka42
looking at the comment on line 37, it sounds like you'll have to add a lifetime to EventMetadata and thread that through everywhere
-
durka42
to be able to remove the 'static
-
snowe_
durka42: huh...
-
theobromine
danieldg: but can't i make a compiler in webassembly and run webassembly in a browser?
-
danieldg
theobromine: sure, you can technically do anything
-
danieldg
but that's not what I would think of by "developing rust on the iphone"
-
danieldg
I mean, you can run Windws XP in webassembly and get IE6 support on your iphone, if you try hard enough
-
steveklabnik
rustc doesn't compile to wasm just yet
-
steveklabnik
clang has, though. so, it's certailny feasable for non-toy projects
-
steveklabnik
you can compile rust code to ios compatbile things already
-
steveklabnik
so in theory you could do it natively with rustc too
-
steveklabnik
danieldg: the "compile code" thing changed a bit. you can't JIT, but you can include an interpreter
-
snowe_
durka42: I don't know if I know enough to convert this to not use a static lifetime :(
-
dunnousername
Does wasm32-unknown-unknown JS interop suck? I've tried that and both emscripten targets and they just won't work
-
steveklabnik
it's very minimal
-
steveklabnik
which can be read as "suck", sure
-
steveklabnik
it's being actively worked on
-
steveklabnik
it will be easy in the near future :)
-
durka42
snowe_: yeah I can't tell from a quick glance whether there's something that blocked Soni from doing it, or if it was just left for later
-
durka42
why do you need it to be non-static though?
-
snowe_
durka42: I'm generating code using quote! and it really doesn't like lazy_static stuff
-
dunnousername
I'm just needing to use XMLHttpRequest, but now when I try to use these targets it doesn't work (vaguely, as it will seem to just do anything to not work)
-
durka42
that's weird, I don't see why that should be incompatible
-
snowe_
I just don't know what I'm doing so that's more likely the cause
-
snowe_
oh cool. ok i got it working with static.
-
snowe_
yeah I just didn't know wtf I was doing.
-
snowe_
alrighty! next question. using proc_macro_attributes is there any way to get a function reference?
-
durka42
like, to what function?
-
snowe_
from my code before.
paste.rs/0Cz
-
snowe_
so instead of having to register the function manually, have the attribute do it.
-
durka42
I mean, in your proc macro you should be able to figure out it's a function and get the name
-
durka42
so you can generate that code
-
durka42
but, I don't see how you could get it into main()
-
durka42
oh I see you'd get it into a new fn called bootstrap
-
snowe_
yeah no worries about getting it into main.
-
snowe_
yeah
-
snowe_
i completely forgot i'd be generating tokens
-
snowe_
and then letting rust figure it out
-
» snowe_ facepalms
-
snowe_
alright. I'm back durka42
-
snowe_
-
snowe_
expected one of `!` or `::`, found `.`
-
snowe_
no clue why it thinks I need to be calling ! or :: on COMMAND_BUS
-
durka42
I think you're generating code at top level that should go in a function
-
snowe_
ah. hahaha
-
snowe_
that's definitely it rofl
-
snowe_
thank you
-
snowe_
also, I tried to use cargo rustc -- -Zunstable-options --pretty=expanded to output the syn generated code, but it didn't output anything.
-
snowe_
so, how would you go about generating code for all attributes into a single function? not sure the best way to accomplish that.
-
durka42
snowe_: so I've experimented with things like this and it's a bit weird because there's order-dependence, right?
-
durka42
like, you want to generate bootstrap() *after* processing all the attributes
-
durka42
and, in my experiment, if you just store all the stuff you want to generate in a lazy_static inside the proc macro crate, and then dump it out in response to another macro call, say gen_bootstrap!(); which you put right at the end of lib.rs, then it indeed works
-
durka42
but I don't know how much to rely on that kind of ordering, it feels fragile
-
durka42
that said, I expect this kind of "register all the things" attribute macro to be pretty common so maybe I've missed an obvious design...
-
snowe_
durka42: yeah that's exactly what I'd like to do
-
snowe_
ah. so it'd need a regular macro call as well?
-
snowe_
dang that's getting a little more hairy...
-
durka42
surely there's another way...
-
snowe_
who can we ask?
-
durka42
maybe it's worth posting in one of the proc macro tracking issues / RFCs if nobody else shows up here
-
sfackler
durka42: that kind of thing is required for custom test harnesses which I think there's some movement on
-
zrneely
I'm writing my first crate using futures, and having a lot of difficulty dealing with typestates - ie, the way that almost everything takes `self` by value. Does anyone know of any crates, blogposts about, or advice for dealing with them more ergonomically?
-
durka42
sfackler: oh?
-
snowe_
durka42: ok. sounds good
-
durka42
sfackler: is it even guaranteed that a given proc macro crate is loaded exactly once?
-
sfackler
don't think so
-
snowe_
durka42: will the derive crate always compile first? like I would put the macro call at the end of the regular lib?
-
durka42
that's what I did in my experiment yeah
-
sfackler
really, it's unstable so you can either see it as *nothing* being guaranteed or exactly the current implementation being guaranteed
-
durka42
that's true heh
-
durka42
now I'm thinking of something truly insane like #[path="/some/named_pipe"] mod input;
-
snowe_
O_o
-
Arnavion
You cannot rely on proc macro attributes being expanded in any order over the whole crate, or even being expanded at all
-
durka42
why the "at all" part?
-
snowe_
Arnavion: you can't rely on them being expanded at all??
-
snowe_
yeah that seems to kinda make them useless...
-
Arnavion
The mod was already compiled previously and hasn't been updated
-
durka42
ah right
-
Arnavion
So if the mod hasn't changed and the proc macro hasn't changed, there's no reason to recompile it
-
durka42
so anything like this type of registration facility will need compiler support like sfackler alludes to
-
Arnavion
In general the only state a proc macro has is its current invocation. Nothing else is guaranteed
-
snowe_
Arnavion: so, what I'm trying to do won't work at all?
-
durka42
it *may* work but it also might break with the next version or if you turn on incremental compilation
-
Arnavion
snowe_: Not with proc macros, no. You'll have to make some kind of pre-processor in a build script
-
snowe_
:(
-
snowe_
what do you mean by preprocessor?
-
durka42
!gh 2318
-
rustbot
[Issue 2318] <closed> Compilation failure <
rust-lang/rust #2318>
-
durka42
whoops
-
durka42
!gh rfcs 2318
-
rustbot
[PR 2318] <open> eRFC: Custom test frameworks <
rust-lang/rfcs #2318>
-
durka42
^ I guess that's what sfackler alluded to
-
durka42
A test framework is like a whole-crate procedural macro that is evaluated after all other macros in the target crate have been evaluated. It is passed the TokenStream for every element in the target crate that has a set of attributes the test framework has registered interest in. For example, to declare a test framework called mytest:
-
snowe_
huh. well that makes sense.
-
durka42
I guess you can basically roll your own proc macros in build.rs by parsing the whole crate and looking for #[register_it] attributes, then generating a module
-
durka42
that's guaranteed to happen before the main crate is compiled
-
durka42
but that kind of... lame :)
-
snowe_
yeah there's no way I know enough about rust to be able to do that.
-
durka42
it's similar to what you're already doing in a way
-
durka42
just fire up syn and feed it... everything
-
durka42
and write out a file
-
durka42
but definitely more involved yeah
-
snowe_
durka42: do you have an example of your gen_bootstrap method? I am just gonna go with this method and learn some stuff.
-
durka42
yeah, I guess I can throw it up on github
-
durka42
I recommend caution though :p
-
neptunepink
There is a benefit to the build.rs way, which is that being able to debug macro output is inherently trivial.
-
durka42
-
durka42
I haven't commented it yet :/
-
durka42
`cargo expand` shows how it works though
-
snowe_
man it really sounds like I should use build.rs...
-
snowe_
I haven't learned about build.rs yet though
-
snowe_
so would that run against a library user's crate?
-
durka42
no a build script only runs when compiling the crate it's attached to
-
durka42
I guess you could provide a function that a user would call in *their* build.rs
-
snowe_
ok, so that wouldn't work either. I want the user to be able to use the attribute.
-
snowe_
hm. ok.
-
snowe_
and thank you for the github upload. I'm looking at it trying to understand.
-
zrneely
I get a lot of 403s clicking on links to tokio.rs from the futures documentation, is that known?
-
snowe_
durka42: do you think it would be possible to write a bootstrap method that takes in the users crates and parses them for the attribute?
-
durka42
if that's done in the build script
-
snowe_
why does it have to be in the build script?
-
durka42
well... if it's called at runtime how is it going to get the source code
-
lf94
mbrubeck, your robinson toy web renderer - how nice do markdown files look?
-
mbrubeck
lf94: it doesn't do text, only boxes. :P
-
snowe_
durka42: oh. I forgot that rust is compiled XD
-
lf94
mbrubeck, big sad face
-
snowe_
durka42: could you explain this error then? I tried to modify your code, but it seems I can't store references to the idents
-
snowe_
-
lf94
If someone implements a renderer with built-in video support, I think it could be usable
-
lf94
for day-to-day
-
lf94
no javascript required
-
durka42
snowe_: apparently Ident contains a raw pointer?
-
durka42
maybe just store it as a string
-
snowe_
I wouldn't be able to have multiple functions with the same name then right?
-
durka42
snowe_: you already can't declare functions with the same name
-
durka42
btw you tempted me into working on the build script hack :)
-
snowe_
durka42: even if they take different params? I didn't realize rust didn't have overloaded methods
-
durka42
it doesn't
-
snowe_
:(
-
neachdainn
How long do gists from the playground last?
-
WindowsBunny
neachdainn: I don't know if github ever deletes anonymous gists. However soon you won't be able to make anonymous gists, so that functionality will break
-
neachdainn
That feature is going away? Why?
-
CognitiveRadiation
I have a match arm ` Expression(Value(ref identifier), _) if self.is_builtin(identifier) => self.eval_builtin(*identifier, arguments),
-
CognitiveRadiation
`
-
CognitiveRadiation
is_builtin takes a reference to the type of the match arm
-
CognitiveRadiation
this code as it stands doesn't compile because I can't move the *identifier out of borrowed content
-
CognitiveRadiation
if I get rid of the `ref`, then it fails to complie because I cannot bind by move into a pattern guard, reasonably enough
-
CognitiveRadiation
I'm not sure how to mkae the compiler happy here
-
CognitiveRadiation
I want to move identifier into self.eval_builtin() if is_builtin() returns true
-
Cetra
CognitiveRadiation: I am not totally sure without seeing your code, can you do a rust playground cut down version
-
Cetra
also there is a little known binding trick you can do that might help?:
doc.rust-lang.org/1.0.0/book/patterns.html#bindings
-
» albel727 isn't sure why "moves value into pattern guard" is even an error
-
albel727
should just not move the value
-
albel727
and give guards a reference
-
WindowsBunny
-
Cetra
Looks like they are being abused
-
albel727
can rust playground paste stuff from its own account, so as to not pollute mine with random stuff I untangle here for other people?
-
Cetra
either that or it could persist it somewhere else
-
albel727
I think it did that originally. probably also got abused :>
-
Cetra
haha, make it so that it's only stored if it compiles to rust
-
Cetra
the mario maker approach
-
emerentius_
/* BINARY DATA */ fn main(){}
-
» albel727 was just going to write /* PEENUS ENLORGEMENT PILLS */ fn main(){}
-
Ralith
binary data enlargement pills
-
WindowsBunny
bunny floof enhancement pills
-
» WindowsBunny floofs Ralith
-
ishanjain28
Hi, I want to discuss this(
rust-lang/cargo #4830) issue here for a moment. It's a issue in cargo.
-
ishanjain28
Person who reported issue ran, cargo install --force --bin svgcleaner --git
github.com/RazrFalcon/svgcleaner and got an error that says "Multiple packages with binaries found"
-
ishanjain28
The --bin flag is to give a binary name and packge names are taken from cargo arguments
-
ishanjain28
What is the use of --bin package?
-
ishanjain28
*I meant --bin flag?
-
ishanjain28
How can 1 package have >1 binaries?
-
ishanjain28
-
ishanjain28
So, I guess, That github issue is because of misunderstanding and not an actual issue in cargo.
-
» Ralith is enhanced!
-
nox
albel727: I may be missing something, but where did you make the playground not create anonymous gists?
-
tom1234
Hey I'm having trouble using the crate quick-error. If I include it in the toml as quick-error, it's found but cant be found from my code as extern crate quick_error. But it's not found as quick_error in the toml
-
albel727
nox: it was speaking about the near future (~2 weeks), when github forbids anonymous gist creation.
-
nox
Oh ok.
-
ishan_
Um, Is there really no package to encode/decode base64/hex in rust?
-
ishan_
*Is there no package in std lib to encode/decode base64/hex in rust ?
-
sebk
!crate base64
-
rustbot
base64 (0.9.0) - encodes and decodes base64 as bytes or utf8 ->
crates.io/crates/base64 <
docs.rs/base64>
-
glandium
-
glandium
(for hex)
-
sebk
!r
-
sebk
...
-
ishan_
I have already found those. I am solving some questions and they don't allow external crates. I wish, base64/hex were included in std lib.
-
sebk
then.. write it yourself?
-
sebk
or copy it
-
glandium
ishan_: hex *is* in std
-
sebk
not allowing crate is ... just stupid
-
ishan_
sebk: That's what I am doing now.
-
glandium
sebk: I hope they never ask to do HTTP requests
-
sebk
:D
-
sebk
glandium: it is not *that* complicated
-
sebk
you can actually do it with plain tcp
-
liranringel
can I see the asm of a specific function in rust playground?
-
sebk
!godbold
-
glandium
sebk: I've done my fair share of HTTP requests with telnet back in the day.
-
sebk
!gb
-
Ndushi
liranringel: try this
godbolt.org
-
sebk
-
sebk
!learn godbold =
rust.godbolt.org
-
rustbot
Learned factoid 'godbold'.
-
sebk
oh. -t
-
glandium
!godbolt
-
sebk
!forget godbold
-
rustbot
Forgotten factoid 'godbold'
-
sebk
!godbolt
-
glandium
it doesn't know godbolt either
-
sebk
!learn godbolt =
rust.godbolt.org
-
rustbot
Learned factoid 'godbolt'.
-
sebk
liranringel: use #[crate_type = "lib"]
-
sebk
and then pub fn test() {}
-
glandium
godbolt doesn't need to explicitly set the crate type
-
liranringel
I'll try it now!
-
nox
Godbolt is so good.
-
ishan_
How do I split u8 slice? I tried <slice>.split(10) but this gives an error that says, "for <'r> u8: std::ops::FnMut<(&'r u8,)>` is not satisfied.
-
bluss
ishan_: split how? For example the .split_at method splits a slice into two parts
-
ishan_
I read a file using include_bytes!(), It gives me a u8 slice. I want to split the content of file at every newline character.
-
bluss
if you want to split it with the value 10 as delimiter, then you chan use .split(|elt| *elt == b'\n')
-
bluss
since split takes a closure
-
ishan_
Thank you so much @bluss.
-
ishan_
One more question, Usually, I pass a integer or a string in split(), Are those automatically interpreted as a closure?
-
ishan_
Why wouldn't using b'\n' or 10 as u8 in split() work in this case?
-
forgottenone
is it possible to ptr::null() to object reference
-
forgottenone
I mean struct reference
-
myeisha
forgottenone: you want to set a reference to null?
-
forgottenone
myeisha: yes, just as a placeholder
-
myeisha
forgottenone: no, but you can use Option<&T> and None
-
forgottenone
myeisha: i see thanks
-
bluss
ishan_: there's no such automatic interpretation as a closure for .split() on a [u8]
-
bluss
ishan_: maybe you're thinking of str::split (string slices), which accepts more than just closures
-
sbw
I got an error[E0225]: only auto traits can be used as additional traits in a trait object in my code:
play.rust-lang.org/?gist=3a9865aae3…b3a0f07d0a9d4bb0d02e&version=stable , but I don't know how to resolve it. I want to save a hashers object list, and get hash result with a hashable item
-
bluss
sbw: Hasher + Sized becomes a self-contradiction and it doesn't resolve this
-
bluss
sbw: Box<Hash> implements Hash and is sized, so it can be used for this
-
bluss
but one must also keep the semantics of the hasher state in mind (and the mut makes that more clear to us)
-
bluss
if you want to compute a new hash, you need to reset or recreate a Hasher value
-
bluss
(and by Box<Hash> before I meant Box<Hasher> implements Hasher, sorry)
-
sbw
ok, I will try this
-
bluss
I think to solve the reset/recreate hasher, you'll need to define a new trait for that functionality (and implement it). I guess basing it on Clone would be the easiest, so not a reset but a create new functionality (but still needs a new trait with a helper method)
-
kindiana
I'm wondering if anyone can help me with this baffling AsRef issue.
-
kindiana
I have a function with this signiture: fn run_command<S>(&self, program: S, args: &[S]) -> Result<Output, Error> where S: AsRef<OsStr> {
-
kindiana
and when I call it like run_command(command, &args[..])
-
kindiana
where args is a Vec<String>
-
kindiana
I get this error
-
kindiana
| 41 | self.run_command(command, &args[..]); | ^^^^^^^^^ expected &str, found struct `std::string::String` | = note: expected type `&[&str]` found type `&[std::string::String]`
-
kindiana
I thought asref was meant to allow you to take both &str and String?
-
kindiana
nevermind, both program and args have to be the _same type_
-
j_ey
kindiana: yeah
-
j_ey
kindiana: you can do S1, S2 of course
-
orjgareewga
Hi! I've got a question about the reql crate (
github.com/rethinkdb-rs/reql). How can one reuse the same Client, tokio Core and reql connection? Feels like a waste to spawn them every time one must sent a message to the DB. Also AFAIK having a DB connection in a global, shared variable is neither attainable nor desireable in Rust. I'm sure this question is valid also for other DBs and things you want to keep a living connection
-
orjgareewga
to...
-
Mateon1
Do sideeffects inside debug_assert! happen in release mode? I.e. is debug_assert!() in release compiled to nothing, or is it just the panic that's removed?
-
Mateon1
Basically I want to do `debug_assert!(do_something().is_ok())`
-
bluss
Mateon1: The code inside doesn't run at all when the debug assert is disabled
-
Mateon1
Ok, so I need `{ let x = do_something(); debug_assert!(x.is_ok()); }`
-
bluss
yep
-
bluss
but the code inside is compiled, in a disabled branch, in any configuration. So it is still type checked
-
bluss
and borrow checked etc
-
gnzlbg
is there a way to create undef from Rust?
-
gnzlbg
let a = mem::unitialized() maybe ?
-
nox
gnzlbg: It's not generally safe to do that. What are you trying to do exactly?
-
gnzlbg
I am calling an llvm intrinsic and need to pass it undef
-
nox
gnzlbg: Then you probably want mem::uninitialized indeed.
-
gnzlbg
is that what mem::uninitialized does?
-
gnzlbg
there is undef and then there is poison
-
nox
gnzlbg: mem::uninitialized returns uninitialised memory that is sound to write to but unsound to read from.
-
gnzlbg
and what codegen does it generate ?
-
gnzlbg
*code
-
nox
undef, IIRC. Check on the Playground or godbolt.
-
gnzlbg
thanks will do
-
gnzlbg
i will give it a try and just check the ir
-
gnzlbg
cargo llvm-ir foo :D
-
Soni
scan+flatten aka flat_map(|x|x) should be made more popular
-
Soni
it's literally the best way to parse strings
-
Soni
or any data
-
nox
What
-
Soni
-
nox
That's a pretty bad way to parse that.
-
theotherphil
I'm confused by a compiler error, and was hoping someone might know what's going on. I've got a function which specifies that a type P: Pixel, but when I try to use an associated type from this trait the compiler complains that P does not implement Pixel. Code here:
gist.github.com/theotherphil/5d05669f5fc116100448f28c5bfee55f Any ideas?
-
gnzlbg
theotherphil:
-
gnzlbg
<P as Pixel>::
-
gnzlbg
try that
-
nox
gnzlbg: That's what they have…
-
theotherphil
I tried this after the first error - this is the last line of the gist, and the line that the compiler is complaining about (possibly not that clear from what I pasted)
-
nox
theotherphil: AH
-
nox
theotherphil: Does Subtype has a default in Pixel's definition?
-
theotherphil
I've seen something like this before with incompatible library versions, but I've deleted my lock file
-
gnzlbg
<P as ::image::Pixel<Subpixel = u8>> ?
-
nox
Either ::image::Pixel ≠Pixel, or Subpixel has a default and rustc gets confused.
-
theotherphil
-
gnzlbg
you are requiring P: Pixel<Subpixel = u8> but then trying to access it as <P as Pixel> instead of <P as Pixel<Subpixel=u8>>
-
Soni
nox: what's wrong?
-
nox
Allocates strings for nothing, and the code flow is very hard to follow in your snippet.
-
nox
gnzlbg: That shouldn't matter.
-
nox
gnzlbg: Then it might not be the Pixel trait you are looking for.
-
gnzlbg
it can matter if Subpixel uses associated type defaults
-
nox
Which it doesn't, they just linked to the trait definition.
-
Soni
nox: I didn't feel like writing long-form
-
theotherphil
gnzlbg: how would I fix this? The compiler rejects <P as Pixel<Subpixel=u8>>::channel_count complaining that it's not valid to specify an associated type in this position
-
nox
Soni: And that's fine, but that certainly doesn't make it "literally the best way to parse strings".
-
nox
theotherphil: Are you 100% certain that Pixel == ::image::Pixel in your code?
-
Soni
nox: it is the best way if you use long-form
-
nox
Soni: No.
-
nox
And you just said you *didn't* write "long-form" (whatever that means),
-
nox
so now you are contradicting yourself AFAIK.
-
Soni
let me write it long-form. still needs scan+flatten tho.
-
nox
There is no need for either of those things to parse strings or any other kind of data.
-
theotherphil
nox: there are no other Pixel types around that I know of. <P as ::image::Pixel>::channel_count still complains that P doesn't implement image::Pixel
-
Mateon1
If you're writing a parser "long-form" whatever that means, you want to write a state machine.
-
gnzlbg
theotherphil: if you leave the part that errors out, does the code type-check ?
-
gnzlbg
lol: <P as Pixel>::channel_count() as usize
-
gnzlbg
you are using that here [val; <P as Pixel>::channel_count() as usize]
-
gnzlbg
that's not going to work, trait methods are not const fn
-
gnzlbg
and even if they were, you wouldn't be able to use them to create a new type inside a function like that
-
nox
gnzlbg: Oh right, hah!
-
gnzlbg
the error message is pretty bad though
-
nox
I wonder why the compiler is complaining about P: Pixel though, that feels like something is misinterpreted in that const context.
-
nox
Yeah.
-
gnzlbg
probably it hasn't done trait resolution yet
-
gnzlbg
or it is not even taking it into account while trying to project the array type
-
gnzlbg
it must have done trait resolution and checked that P: ::image::Pixel
-
gnzlbg
so it is more likely that the logic for consts does not account for trait methods / traits in general
-
theotherphil
gnzlbg: as written it doesn't type-check. I've replaced the bits it's complaining about with a constant and fixed the rest of the type errors. It now compiles with that bit commented out, but doesn't when I uncomment it
-
gnzlbg
associated consts cannot be used in that position either
-
gnzlbg
theotherphil: what you are trying to do cannot ever work; do you understand why?
-
theotherphil
gnzlbg: I don't. I've done something that looks identical to me elsewhere and that worked
-
gnzlbg
-
gnzlbg
that's a minimal working example
-
gnzlbg
you are trying to create a new type inside your function: [i32; <P as Pixel>::channel_count()]
-
gnzlbg
channel_count is a dynamic function
-
gnzlbg
but the array length must be known at compile-time
-
theotherphil
gnzlbg: ah, this works if I replace that with vec![...]. Which is what I intended in the first place. I was just totally misled by the compiler error message
-
gnzlbg
yeah that works
-
theotherphil
Sanity check: the compiler error here is nonsense, right?
-
theotherphil
If so I'll add it to the thread in rust internals about compiler error complaints/requests
-
theotherphil
Thanks for the help
-
gnzlbg
-
gnzlbg
it might be a duplicate, but i couldn't find anything similar
-
theotherphil
Ah, great, thanks!
-
nox
gnzlbg++
-
ray
hi, how easy is it to marry rust and python`
-
ray
and is there xslt and xsd support?
-
steveklabnik
ray: lots of people are doing it, there's tons of crates to make it easier, like milksnake and pyo3
-
steveklabnik
i haven't done much xml processing so i know there are generic xml libraries but not sure about xslt/xsd
-
ray
unfortunately stuck with xml for various things
-
ray
currently using lxml for these tasks
-
steveklabnik
-
steveklabnik
for example
-
steveklabnik
ray: well, there is a lxml wrapper
-
steveklabnik
!crate libxml
-
rustbot
libxml (0.1.2) - A Rust wrapper for libxml2 - the XML C parser and toolkit developed for the Gnome project ->
crates.io/crates/libxml <
docs.rs/libxml>
-
ray
steveklabnik: doesnt look like it ships with xsd and xslt bindings
-
steveklabnik
gotcah
-
steveklabnik
yeah
-
steveklabnik
i see that now
-
ray
i know xml is unpopular these days
-
durka42_
welp I ended up writing the build script proc_macro_attribute hack that snowe, Arnavion and I were talking about last night
github.com/durka/macbuild
-
steveklabnik
oh
-
ray
if you are writing softare professionally however everythings full with xml
-
steveklabnik
looks like shep has some libraries
github.com/shepmaster/sxd-document
-
SovietBear
which thread pool crate would you recommend? (not using futures, not scoped)
-
ray
e.g. sap idocs and soap apis
-
steveklabnik
-
steveklabnik
SovietBear: i still prefer scoped threadpool. it's like 150 lines of readable code
-
steveklabnik
even if you don't plan on using the scoped aspect, it's still good, imo
-
SovietBear
steveklabnik: can it do non-scoped threads too?
-
steveklabnik
scoped threads are a superset of non-scoped threads
-
steveklabnik
no?
-
SovietBear
steveklabnik: why am i not getting the backtrace from the original panicked thread?
pastebin.centos.org/572586/09415715 (the one that caused "attempt to subtract with overflow")
-
ray
-
ray
"In the future, I hope to add support for XSLT 1.0."
-
ray
tl;dr no xslt crates available i guess
-
ray
i should take off a year from work and implement xslt 3.0 xD
-
ray
if i could
-
SovietBear
ray: you could crowdfund it
-
SovietBear
or find a company as sponsor
-
ray
yeah, was joking, no idea if i could manage to get the full parser implemented :)
-
steveklabnik
ray: yeah, i'd be nice. rust is still young, so the long tail of libraries is filling out
-
ray
yeah, i guess it will take another 2-3 years until you can consider using it
-
steveklabnik
i mean
-
steveklabnik
how big is the libxml api surface here?
-
steveklabnik
you could bindgen it up, maybe
-
steveklabnik
it's not the *nicest* thing
-
ray
yeah, thats probably the most feasible thing
-
ray
everyone's stuck with libxml bindings
-
ray
which were up to date around 2000
-
ray
there's saxon C
saxonica.com/saxon-c/index.xml which is somewhat more up to date
-
cheers-M
would someone be able to explain the difference between linear and affine types to me? (:
-
steveklabnik
cheers-M: so
-
steveklabnik
linear: must be used exactly once
-
steveklabnik
affine: must be used at most once
-
steveklabnik
1 time vs 0-1 times
-
steveklabnik
that's it
-
steveklabnik
SovietBear: i am not sure, tbh.
-
SovietBear
steveklabnik: when another non-main thread crashes, i DO get the backtrace from that thread, just not with this one
-
cheers-M
oh, alright. i was reading a discussion where people were talking about the two as if there were other differences
-
SovietBear
but they are spawned the same way
-
cheers-M
or perhaps certain properties granted by their attributes. safety guarantees etc
-
cheers-M
anyway, thanks!
-
steveklabnik
cheers-M: it's also hard because some people call both "linear"
-
cheers-M
ah. strange
-
SovietBear
steveklabnik: how can i find out why i'm not getting the backtrace?
-
steveklabnik
i don't know
-
WindowsBunny
SovietBear: What platform?
-
SovietBear
WindowsBunny: windows 8.1
-
WindowsBunny
SovietBear: So you're saying a thread is panicking with subtraction overflow, and your panic hook isn't being run on that?
-
SovietBear
WindowsBunny: right
-
SovietBear
-
happyhalfdane
Hi there I'm having an issue with values not living long enough in function. I have a data structure that contains elements and I wanna get a reference to that element and return it how can I do it? Here is the code I have at the moment
-
happyhalfdane
-
WindowsBunny
SovietBear: I can never remember that you and Boscop are the same
-
WindowsBunny
SovietBear: I'm not entirely sure
-
SovietBear
WindowsBunny: is this a rustc bug?
-
WindowsBunny
I honestly don't know
-
Limeth
How would I move all values in an array by one index? I currently rely on cloning the values, but maybe it'd be possible to optimize it.
-
talchas
you could do something with swap
-
talchas
if you've benchmarked it and it's a performance bottleneck, you could use unsafe code to make sure you don't do unnecessary (shallow) copying
-
Limeth
oh, that could definitely work
-
talchas
(since I would be surprised if the optimizer managed to turn a swap loop into memmove)
-
Limeth
hopefully it gets optimized even further by the compiler, but I'm satisfied even with just using swap instead of having to clone the values. Thanks!
-
» albel727 thought someone already created an array iterator crate
-
nox
albel727: ArrayVec has that IIRC.
-
albel727
hmm, it does.
-
Soni
-
Soni
just for you
-
nox
I have no idea what you mean by that gist.
-
Soni
-
Soni
into that[
-
nox
You may be interested in reading literature about implementations of parsers, because that was vastly unneeded.
-
snowe_
oh hey it's Soni! did you ever rewrite this without the static requirement?
-
snowe_
-
Soni
snowe_: I have abandoned my eventbus because I don't believe events are the way to go for something like rust
-
snowe_
ah :(
-
Soni
you're welcome to fork it tho
-
snowe_
maybe when I get more comfortable with rust.
-
myeisha
heh, that looks familiar
-
snowe_
right now I don't even know how to solve this error.
paste.rs/p76
-
Soni
&fun_list?
-
snowe_
didn't work either.
-
Soni
uh huh
-
Soni
what
-
Soni
tried #rust-beginners ?
-
snowe_
i'll try over there
-
emerentius_
fn(&mut T) doesn't implement Hash + Eq
-
emerentius_
not that I'm seeing a good reason for that
-
Soni
other options: find someone who has created a high-performance, extensible event bus in rust
-
Lymia
What's the future of box_patterns exactly?
-
Lymia
It's been in nightly for a long time, it seems
-
snowe_
emerentius_: is there an alternative to what I'm trying to do then?
-
jeduardo
Unable to negotiate with 172.17.0.1 port 52374: no matching host key type found. T
-
jeduardo
oops, sorry
-
emerentius_
snowe_: you could write a newtype around the fn and manually implement PartialEq, Eq and Hash for it
-
emerentius_
in terms of the fn's address, so through a 'as usize' cast
-
snowe_
o.O
-
emerentius_
annoying boilerplate but it should work
-
emerentius_
I'm wondering why "impl<Ret, A> Hash for fn(A) -> Ret" doesn't catch A = &mut T
-
Soni
?Sized?
-
Soni
(maybe?)
-
Soni
(I have no idea what I'm talking about)
-
emerentius_
&mut T is Sized
-
snowe_
emerentius_: so the docs say that fn implements hash, eq, and partialeq so I don't really understand what I need to do.
-
snowe_
-
ray
does Box do more than new/malloc?
-
ray
or just use Box whenever you'd have used either one in C/C++?
-
emerentius_
snowe_: looks like a bug in the trait system
-
snowe_
O.O
-
snowe_
i would hit a bug as soon as I try to start using rust again.
-
emerentius_
snowe_: seems to be an interaction with the higher ranked trait bounds
-
emerentius_
this for<'r> fn(&'r) stuff
-
neachdainn
How would one instantiate a Box<DST>?
-
snowe_
is that in the doc somewhere?
-
emerentius_
I'm filing a bug
-
snowe_
oh! awesome.
-
snowe_
you're sure it's a bug?
-
Soni
-
snowe_
well that sounds exactly like what I'm dealing with.
-
Soni
it is
-
Moomoc
What's the best way to get the pthread id (pthread_t) from the currently runnign thread? I can only think of let id: pthread_t = transmute(thread::current().id())); I hope there's something better.
-
emerentius_
trait EnsureEq: Eq {}; impl<'a, T> EnsureEq for fn(&'a T) {}; works
-
emerentius_
it's the HRTB that break it
-
occultus
Moomoc: there's no guarantee that .id() has anything to do with the platform's thread ID
-
Moomoc
occultus: I know, but my code is specific to one platform anyway
-
emerentius_
not that it's actually a trait bound
-
Moomoc
occultus: So is it acceptable in this case? Any alternative?
-
Moomoc
occultus: I need to hand something over to the C pthread interface
-
snowe_
emerentius_: like this?
paste.rs/6jV
-
snowe_
that still results in an error for me.
-
occultus
Moomoc: actually, it might be guaranteed to *not* be related
-
emerentius_
snowe_: that doesn't implement anything, it would result in a compile error if fn(&'a T) wasn't Eq
-
Moomoc
occultus: How that? I looked into std and there it is struct ThreadId(pthread_t).
-
occultus
Moomoc: thread::current().id() was "1" when I ran it, which is definitely not the pthread id
-
snowe_
emerentius_: I don't really understand...
-
emerentius_
it's like a type level assert!
-
emerentius_
EnsureEq requires Eq to be implemented
-
Moomoc
occultus: On which platform are you? There's an implementation for Linux and one for unix, I'm using the unix one on my platform.
-
emerentius_
but implementing EnsureEq doesn't give you Eq
-
occultus
Moomoc: Linux here
-
The_8472
use the libc crate to get the pid?
-
occultus
Moomoc: if you're calling into C already, why not just use the pthread interface?
-
snowe_
emerentius_: oh so you are saying that Eq has to be implemented since that code doesn't fail to compile.
-
occultus
Moomoc: the problem with using ThreadId directly is that a future version of Rust might use something that is not the pthread id, breaking your code
-
Moomoc
occultus: ah right. I didn't think about that. Do you know by any chance what the name of the pthread function might be to get the handle for the current thread?
-
Moomoc
occultus: yeah, that absolutely makes sense.
-
occultus
Moomoc: pthread_self returns a pthread_t
-
emerentius_
snowe_: yeah
-
emerentius_
fn(&T) is really for<'r> fn(&'r T)
-
emerentius_
but fn(&'a T) is just that
-
emerentius_
I managed to build a HashMap of reference taking functions at least
-
emerentius_
-
emerentius_
You might be able to sprinkle generic lifetimes everywhere and have them adapt to whatever's necessary
-
emerentius_
given that they're not bound to anything
-
emerentius_
might also break on sth, I don't know
-
Moomoc
occultus: Indeed, pthread_self() is what I really want. Thanks! I was just trying to get a handle to the main thread. Thanks for the help
-
emerentius_
but lifetimes subtype so whatever the smallest lifetime is that any of your functions take
-
emerentius_
longer lifetimes are also acceptable
-
» snowe_ cries
-
snowe_
emerentius_: I understood some of what you said
-
emerentius_
snowe_: treat your HashMap<fn(&mut T), i32> as a HashMap<fn(&'a mut T), i32>
-
emerentius_
add a lifetime parameter to your functions / traits as necessary
-
Arnavion
durka42_: Now build your own cfg-handling so that you can understand #[cfg]'d mods ;)
-
emerentius_
actually, lemme check if this could work in some simple cases
-
emerentius_
could very easily fail
-
durka42_
Arnavion: noooooo :)
-
durka42_
Arnavion: also macro-generated mods in general won't work obviously
-
Noldorin
how do I use rustup to download the stdlib src for the stable toolchain? I only seem to have it for nightly
-
snowe_
emerentius_: man that change is propogating so far through this code...
-
emerentius_
doesn't work anyway
-
snowe_
emerentius_: how'd you test?
-
Arnavion
Noldorin: If you added the rust-src component it should download the component for every toolchain. If it didn't for any non-default toolchain, try reinstalling the toolchain
-
snowe_
maybe Arnavion knows
-
durka42_
snowe_: ICYMI github.com/durka/macbuild
-
snowe_
durka42_: > This code is bad and you shouldn't use it!
-
snowe_
XD
-
snowe_
yeah I stopped with the macro stuff just to get the rest of the library going, and I was gonna come back to your code later
-
snowe_
but of course I immediately hit a bug in the trait system.
-
emerentius_
snowe_: made a map with the build_hashmap I posted before, inserted a `fn foo<'a>(&'a mut u32)`, got it back out and tried to call it
-
emerentius_
couldn't
-
» penguin42-M went to a very pleasent little Rust meetup in Manchester, UK on thursday; nice there are a few groups like that
-
Noldorin
Arnavion, hrm. just tried, no luck. something special about how VSCode interacts with it maybe?
-
Arnavion
Noldorin: If you mean rls, rls has never looked in the right place for rust-src for me
-
Noldorin
Arnavion, yes sorry, rls
-
Arnavion
Noldorin: It always tries to look under the workspace directory instead of where it actually is
-
Noldorin
Arnavion, oh right. how did you configure?
-
Noldorin
I see...
-
emerentius_
-
snowe_
emerentius_: Oh!? you couldn't call it?? why would that be?
-
Arnavion
Noldorin: I didn't. I left it broken. I know that people have made symlinks in their workspace directory to make it work
-
emerentius_
snowe_: it inferred a minimum lifetime that the data I supplied didn't have
-
Arnavion
-
taktoa
anyone know of a library for interning strings that supports interning a &std::path::Path (string-cache and string-intern both seem to take an &str, which is problematic since paths are not guaranteed to be UTF-8; they are just bytestrings)?
-
Noldorin
Arnavion, thanks
-
taktoa
I think maybe
docs.rs/hashconsing/0.9.0/hashconsing might work but I'm not sure
-
snowe_
emerentius_: oh that's without specifying a lifetime. I thought you had specified a lifetime. Would doing what you said earlier work then?
-
emerentius_
snowe_: the link is the workaround, not the failing test code
-
taktoa
-
snowe_
emerentius_: ah.
-
snowe_
emerentius_: that results in a very strange error on my side.
paste.rs/ULR
-
jpernst
is there a stable way to deallocate a box without dropping the contents (unsafe is fine)?
-
kimundi
jpernst: I don't think so - at least not without doing something very exotic. If you can control the box though, you could put a ManuallyDrop in there. Or if not deallocating the box is fine, you could forget() it
-
jpernst
yeah, i was hoping to avoid manuallydrop, but oh well, no big deal
-
jpernst
that means i'll have to make a newtype wrapper, which i really didn't want to do
-
jpernst
i guess i could just manually add a drop flag to the struct
-
emerentius_
jpernst: std::mem::forget(*box_)?
-
kimundi
hmmm, what emerentius_ wrote could work - it moves the contents out, and then deallocates the box - then you just forget the contents
-
jpernst
hmm, yeah
-
jpernst
that's good, i like that
-
emerentius_
snowe_: I need more context for that, what's Command and what's the signature of register on COMMAND_BUS
-
jpernst
this is all a workaround for lack of emplacement, but you gotta do what you gotta do
-
snowe_
emerentius_: here is the entire codebase.
github.com/snowe2010/pes
-
Lymia
urg :(
-
Lymia
I tried turning on the warnings for in-band lifetimes
-
Lymia
it also warns for code in #[derives] :(
-
ray
how do i know for which generic parameter i should use an assoc type rather than a type parameter?
-
ray
is there a rule of thumb?
-
Arnavion
ray: If the caller controls it, it's a type parameter. If the implementation controls it, it's an associated type
-
Arnavion
ray: For example, an iterator of T can only be an iterator of T, so Iterator::Item is an associated type
-
emerentius_
snowe_: are you saving f in CommandHandlerId?
-
emerentius_
any by f I mean the fn(&mut T)
-
snowe_
emerentius_: all of that code was copy and past from Soni's library, so I'm not sure what is meant to happen.
-
ray
Arnavion: but isnt an iterator of T Iterator<T> ?
-
Soni
I mean it was written back in rust 1.0 or so
-
Soni
so uh
-
Soni
y'know
-
Soni
:p
-
snowe_
XD
-
Arnavion
ray: Iterator does not have any type parameters. Iterator::Item is an associated type.
-
Arnavion
ray: For the reason I wrote.
-
ray
so you basically hide the parameter inside the type because its irrelevant to the user?
-
Arnavion
ray: It's not irrelevant to the user. It's just out of the user's control.
-
ray
how could the user control Iterator<T>
-
Arnavion
They can't. That's the point.
-
ray
you cant make an Iterator<User> to an Iterator<Database> anyways if you iterate over a list of databases
-
ngc0202
What crate should I use for a config file for my project?
-
ngc0202
I'm not really sure what style of config file I want
-
ray
because a List<Database> always returns an Iterator<Database>
-
Arnavion
ngc0202: Rust projects usually use TOML or JSON, both using serde
-
ngc0202
Definitely not JSON :)
-
ngc0202
yeah I guess TOML works
-
ngc0202
I really just need key-value, value being mostly numbers and sometimes lists of IP addresses
-
ray
Arnavion: basically i dont know what "the user controls controls the parameter" means
-
emerentius_
ray: if Iterator were generic you could make a struct that could return different types on calling .next()
-
ray
i see, so there's a fundamental difference between interfaces in java and traits in rust
-
ray
stuff looks like methods but its really just a function
-
ngc0202
how are TOML sections represente n the decoded struct?
-
ray
emerentius_: you could do that by defining different impls for the struct based on the Iterator type right?
-
Soni
(someone please tell snowe_ to use someone else's library thanks)
-
ray
like impl Iterator<String> for Vec<String>
-
ray
impl Iterator<Integer> for Vec<String>
-
emerentius_
yes
-
snowe_
haha Soni I tried to use this library
github.com/bonifaido/rust-eventbus but it didn't have metadata and I thought metadata was a good idea.
-
ray
ty, took me maybe a year to get this :)
-
Ralith
ngc0202: a toml section is just a key whose value is a table
-
sleffy
Is there a reason that `Any` does not have `downcast_*` for `Any + Send + Sync + 'static`, only `Any + Send + 'static`?
-
sleffy
Is it unsafe to have `Any + Send + Sync + 'static` and` downcast_ref`?
-
ngc0202
Ralith: ahh, interesting
-
sleffy
I mean, I assume there must be a reason
-
ngc0202
I can make a struct and impl Deserialize for it, and just pass it the config file, and it'll come out all nice, right?
-
sleffy
ngc0202, toml/serde? Yes, with some restrictions.
-
ngc0202
what kind of restrictions?
-
sleffy
ngc0202, there's some table ordering stuff iirc
-
sleffy
I don't remember the specifics. They aren't very troublesome, but in some cases you'll need to add some annotations
-
shep
ray: I'd *love* for someone to help out with SXD
-
shep
I think that Rust could be a wonderful language to deal with XML
-
ray
indeed
-
ray
shep: and throw out all the xml madness
-
ray
like get rid of xinclude, entities
-
ray
shep: whats the difference between this lib and xml-rs
-
shep
ray: last I checked, xml-rs has no concept of a DOM
-
ray
shep: my experience is: writing shitty compilers with yacc in university courses, a lot of java/python/js/php and very little C/C++/Rust
-
ray
also 2 small kids and full time job ;D
-
shep
it was just a pull parser. SXD has a pull-parser internally, but also a DOM, and most of XPath 1.0 is in sxd-xpath
-
ray
shep: did you check newer xpath specs?
-
shep
I've skimmed them
-
shep
But they went from like... 50 pages to 300 pages
-
ray
must be the reason why the libxml guys gave up
-
shep
Yeah, I think maybe only one of the Java libraries has anyting past XPath / XSLT 1.0
-
ray
saxon afaik
-
shep
there's some neat things in there, but it seemed like it was way over engineered
-
shep
ray: there's even some very fun parts of XML + Rust that remain, such as really supporting Serde
-
ray
oh, we're already at xpath 3
-
ray
collection()/(let $a := . return function() { $a })
-
ray
looks like they've built js into it
-
shep
right?
-
nox
XPath: not even once
-
ray
the sad thing is that all standards supported by libxml are lacking
-
ray
almost impossible to not run into issues when using it
-
SovietBear
steveklabnik: where is the revised version of this logo?
b.thumbs.redditmedia.com/W8uCVAhOkN…hF9AyYvJZrvPJLexMQEpjyzA4Xw2F9A.png what's the current state?
-
ray
shep: did you look at xsd 1.1 yet?
-
shep
ray: I've also discovered that libxml doesn't validate that element/attribute names are even valid
-
shep
like, IIRC, you can say an element name is `\1ha\2`
-
ray
-
ray
looks doable i guess
-
shep
I havne't looked at it in a while, TBH
-
quasikaote
what would be a benefit of xml parsing rather than rewriting something to JSON? is it just more expansive?
-
shep
ray: you think you'd be interested in contributing? If so, we can find something interesting and work up some mentoring instructions
-
ray
quasikaote: there's a lot of xml floating around
-
ray
shep: sure, but i have very little time
-
shep
quasikaote: for *new* stuff, probably not much, but, yeah, interoperation
-
ngc0202
is there a guide for making links to other items in rustdocs?
-
ray
quasikaote: xml can do neat things sometimes like reformatting xml is neat with xslt
-
ray
quasikaote: and sometimes JSON is too weak
-
Soni
snowe_: metadata is just a weird thing that probably doesn't improve performance at all but I tried
-
quasikaote
hmm. Maybe I'll look into it more once I get more of rust down. I know Openbox uses XML for menus and stuff
-
ray
a lot of madness went into js which in turn went into JSON
-
shep
Yeah, XSLT is a pretty great tool, for what it was *designed* for. It's also used beyond that and it's real bad there
-
ray
like everything that has anything to do with numbers
-
quasikaote
yeah, I admit, XML is much easier to read than JSON for me
-
ray
i really like JSON but there are some valid use cases for XML as well
-
quasikaote
hmm I'll do some research into that stuff. I kind of need to pick one or the other and focus on it. I didn't realize XML was still being used these days
-
shep
I think it's totally fine to use JSON in new stuff
-
ray
you need XML for older SOAP apis or for SAP integration
-
shep
The only things "missing" from JSON are comments and (IMO) namespaces
-
ray
basically if you are building webshops you cant get around it
-
shep
and the silly restriction on trailing commas ;-)
-
quasikaote
lol. good to know.
-
shep
XPath can also be useful for HTML world
-
shep
although XML and HTML are further away than is wonderful
-
ray
right, its like a better version of css selectors
-
shep
there's some latent interest in getting sxd-xpath to work with html5ever
-
shep
but I've never really looked into it in detail
-
ngc0202
can I link to the std doc from my docs
-
sfackler
sure
-
ngc0202
what would that look like?
-
sfackler
a normal markdown link
-
ngc0202
oh, wait should I use the online doc url?
-
ray
shep: I'll play around with your lib a bit
-
ray
try if i can get something minimal with XSD going
-
nox
ray: You may be interested by the Transit format, btw.
-
nox
(Or not, which is fine too.)
-
nox
shep: Was it really '\1ha\2' or just an example?
-
nox
shep: CSS selectors are all you need on the Web, XPath is unneeded.
-
shep
nox: I'm pretty sure it was a ASCII control character, but I don't remember which
-
shep
Also, CSS (until maybe CSS 4) doesn't have a "go back up", which XPath does
-
nox
shep: Ack! Was just curious. NameStartChar is surprisingly large
w3.org/TR/2006/REC-xml11-20060816/#NT-NameStartChar
-
nox
shep: What do you mean by go back up?
-
shep
/a[../@id = 'moo'] ("find all elements named 'a' that have a parent with an 'id' attribute of 'moo')
-
shep
that example is rewritable
-
shep
others are not
-
shep
lemme see if I can remember one..
-
nox
shep: Ah I remember, but I can't remember the use case. :)
-
shep
But I do know that capybara (popular Ruby HTML testing framework) translates all CSS selectors to XPath
-
nox
shep: "For example, the following selector matches only <a> elements that contain an <img> child: a:has(> img)"
-
nox
Before that, you could select the img but not the a.
-
shep
is that CSS 4?
-
nox
Yes.
-
nox
-
nox
CSS 4 isn't a thing though, that's selectors level 4.
-
shep
true
-
shep
I get lazy in terminology ;-)
-
nox
No problem. :)
-
shep
-
nox
shep: Yeah, I disagree on some points. :P
-
nox
shep: I had
w3c/csswg-drafts #1027 in mind because :matches() is a pain to implement.
-
ray
btw, I'm missing something like: cargo add package
-
shep
ray: before I forget, please feel free to file an issue on sxd-document / sxd-xpath if you'd like to try something, and I'll give as much help as I can!
-
shep
ray: to add it to your Cargo.toml?
-
ray
yes
-
shep
-
ray
meh :D
-
ray
i kinda hate the nodejs philosphy
-
shep
`cargo install cargo-edit` `cargo add foo`
-
nox
ray, shep: I diss XML because I do a browser where it's not all the rage anymore, but I do realise tools are needed anyway so props to you for working on that.
-
nox
ray: There is a cargo-add on crates.io IIRC.
-
nox
!crate cargo-add
-
rustbot
cargo-add (0.2.0) - Add dependencies to your Cargo.toml from the command line (deprecated in favor of cargo-edit). ->
crates.io/crates/cargo-add <
docs.rs/cargo-add>
-
nox
Oh.
-
nox
Disregard me.
-
ray
nox: yeah, there are some really bad things in xml
-
ray
but it serves as a warning to other people :D
-
nox
ray: Dissing it is all great and fun until the bank that processes your payments insists on using XML.
-
ray
or your health care provider has XXE vulnerabilities
-
snowe_
Soni: oh you were attempting to use it to improve performance? in most event sourcing frameworks, metadata is used to add information to every event, like timestamps, tenant identifiers, etc.
-
Soni
snowe_: "metadata" is info about the event type
-
Soni
that stuff just goes on the event instance themselves
-
Soni
instances*
-
snowe_
hmm. not in my experience, but if that's how you were using it then it makes more sense why those methods were being called in post method
-
ngc0202
how come the rustdocs doesn't show anything at all regarding my #[derive(Deserialize)] on this struct
-
dtolnay
ngc0202 it is a rustdoc bug
rust-lang/rust #36922
-
ngc0202
huh, ok
-
snowe_
Soni: why did you decide an event weren't the way to go in rust?
-
Soni
snowe_: I prefer "composition" nowadays (that's not the right term but w/e)
-
snowe_
like actors?
-
Soni
events are useful if you need modules
-
Soni
what I'm doing now is useful if you need modularity
-
Soni
rather than using events to parse IRC messages, and having IRC messages natively extensible, I'm actually going for a much more modular approach, where I have IRC messages made up of multiple parts
-
Soni
and there's a trait for a simple RFC-compliant IRC message
-
snowe_
ok. I think I understand.
-
Soni
but you can build "trait Ircv3Message: IrcMessage {}"
-
Soni
and so on
-
Soni
and then those can be further refined
-
Soni
and you provide crates with basic impls
-
snowe_
gotcha
-
Soni
so there would be a crate for a full IRCv3 implementation, separate from the IRCv3 traits, and so on
-
Soni
and someone could come along and make a crate with an IRCv3 + CTCP-S implementation
-
Soni
it's not as flexible as events but it's much more performant
-
Soni
you can even have subroutines to parse basic IRC commands, also in a crate, in a way that any crate/implementation can use
-
Soni
it's a tradeoff between runtime flexibility and performance
-
Soni
altho if anything, this increases compile-time flexibility
-
Soni
and I feel like the rust way is all about compile-time
-
snowe_
yeah you lost me
-
Soni
sorry
-
Soni
maybe it's just what I'm doing that shouldn't use an event system
-
Shayanjm
I'm having some issues compiling my program due to "undefined reference" errors being thrown by a library which uses bindgen. Specifically, the library is "rust-hyperscan"
-
Shayanjm
I've verified that hyperscan (the c library being bindgen'd) has been installed correctly and that it links (ran gcc -lhs)
-
emilio
Shayanjm: you need to link it into your rust program, bindgen doesn't take care of that
-
Shayanjm
-
Shayanjm
-
Shayanjm
If I don't pass HYPERSCAN_ROOT, it throws an error saying that hyperscan isn't installed. If I pass HYPERSCAN_ROOT, it throws a whole bunch of undefined reference errors.
-
mib_kmvjos
hi all, I'm trying to wrangle with some lifetimes, and I've managed to reduce my question to a small example:
play.rust-lang.org/?gist=7d57b19235…ef6af9aa615fecbf8236&version=stable . can anyone help me understand why the borrow check fails if line 6 is uncommented?
-
Shayanjm
also ldconfig -p | grep hs seems to output correctly so I'm not sure what's going on
-
emilio
Shayanjm: looks like `HYPERSCAN_ROOT=/usr/local` should work, looking at that code
-
Shayanjm
let me try it, give me one sec
-
Shayanjm
same undefined reference errors
-
Shayanjm
I don't even know how to reason about this :\
-
emilio
Shayanjm: hmm... looks like it's trying to call `_hs_scan` instead of `hs_scan`... can you look at the generated bindgen output? Also, is this windows by any chance?
-
Shayanjm
Nope, this is CentOS7
-
ray
hm, chaining methods sometimes leads to "does not live long enough errors"
-
ray
is that a non lexical lifetime issue=
-
Shayanjm
and yeah gimme a sec
-
mib_kmvjos
ray: good question, I'm not sure
-
shep
ray: depends on the methods ;-)
-
ray
e.g. let doc = parser::parse(xml.as_str()).expect("Failed to parse"); works
-
ray
let doc = parser::parse(xml.as_str()).expect("Failed to parse").as_document(); doesnt
-
Shayanjm
emilio: is my assumption right that the bindgen output would live in src/raw_bindgen.rs?
-
shep
ray: as_document returns a value with a reference to the value returned by `parse`
-
shep
-
emilio
Shayanjm: ooh, I see what's going on there... So it doesn't run bindgen at build time, but checks out the bindings...
-
emilio
Shayanjm: one second
-
shep
`pub struct Document<'d>`
-
emilio
mib_kmvjos: so the issue with `Cow<'a, Foo<'a>>`, is that you're telling the compiler that the lifetime of the `Cow` and `Foo` is the same
-
Shayanjm
Sounds good, and thanks again for your help on this emilio. I've been bashing my head against the wall for a while now trying to figure out wtf is going on
-
emilio
mib_kmvjos: which is not the case
-
ray
shep: ah i see
-
ray
so kinda needs a tmp value until the end of the block
-
ray
so the ref is kept alive
-
emilio
mib_kmvjos: so you need two lifetimes there, let's call `'a` and `'b`, and you need to make sure that one outlives the other
-
ray
at least for the lifetime checker
-
shep
yep. So NLL would not help here, since the `Package` would be dropped
-
emilio
mib_kmvjos: so `<'a, 'b: 'a>` and `Cow<'a, Foo<'b>>`,
-
ray
whats the purpose of Package btw?
-
emilio
Shayanjm: so what's happening is that that crate checks in the bindings, and the bindings were generated on Mac OS
-
emilio
Shayanjm: Mac OS has weird backend mangling which adds an undescore to the symbols
-
Shayanjm
hmm interesting
-
Shayanjm
what's the recourse for this?
-
emilio
Shayanjm: bindgen adds the `#[link_name]` attribute for that case because for C++ trying to figure out the right symbol is a pain. In this case it shouldn't be needed
-
Shayanjm
I see cfg(feature = "gen") in the build.rs, so would I just need to run cargo build --features gen to course correct here?
-
shep
ray: yeah....
-
shep
It's the best way I could figure out how to make the borrowchecker work for me
-
emilio
Shayanjm: deleting the `#[link_name = "\u{1}_hs_alloc_scratch"]` lines should work. Looks like `--features gen` should make bindgen run at build time, so that should work too
-
shep
Basically, the `Package` contains all sorts of unsafe chunks of memory to deal with the web of links that is a DOM
-
Shayanjm
Sweet, let me try this
-
shep
and when you get a `Document`, you aren't able to move those chunks of memory
-
shep
(because of the reference)
-
mib_kmvjos
emilio: if I have to decorate Foo with the additional lifetimes, then I won't be able to have this sort of recursive type structure, right?
-
Shayanjm
emilio: so cargo build --features gen compiles correctly, but then if I cargo test it's the same issue with the undefined references
-
emilio
Shayanjm: you presumably need to `cargo test --features gen` too, right?
-
Shayanjm
ah that would make sense lmao
-
Shayanjm
one sec
-
Shayanjm
okay awesome, so that works
-
Shayanjm
to that point though, how would I pass --features gen to the crate when I'm compiling the larger project that implements it?
-
shep
[dependencies] foo = { features = ["gen"], ... }
-
Shayanjm
cargo build --release still throws the undefined errors if compiling from the parent project, presumably because bindgen isn't being run at compile for rust-hyperscan
-
emilio
Shayanjm: you need to add the `features = ["gen"]` to the Cargo.toml
-
Shayanjm
awesome, thanks shep && emilio
-
shep
haha, I just swooped in at the end, it's all emilio
-
Shayanjm
running a full rebuild right now, it's looking good so far :)
-
Noldorin
hrm, there's no way to wrap a type that's not Send and make it Send, is there?
-
emilio
mib_kmvjos: that's true, but that's because that recursive structure doesn't make much sense, I think
-
glandium
I wish it were easier to add trait bounds depending on cfg(feature)
-
emilio
Noldorin: struct MyType(TypeThatIsNotSend); unsafe impl Send for MyType {} should work
-
emilio
Shayanjm: happy to help! :)
-
Noldorin
emilio, I don't really want to do this though. I just want to make a guarantee by wrapping it.
-
mib_kmvjos
emilio: well I'm trying to put together a protobuf-like structure where there can be messages that have, as children, other messages that may or may not be borrowing their data
-
mib_kmvjos
emilio: I think that fits with rust's single owner paradigm
-
emilio
mib_kmvjos: Right, but that means that all the borrowed values need to come from the same place, right, and thus have the same lifetime, right?
-
Shayanjm
emilio: worked perfectly, can't thank you enough!
-
durka42
glandium: hmm that's another use case for trait aliases I suppose
-
Shayanjm
also TIL about macOS's weird name mangling
-
Shayanjm
that's a really good insight
-
glandium
durka42: yet another unimplemented rfc
-
durka42
I know :(
-
occultus
Noldorin: why does it need to be send? if you want to "send" non-Send data between threads there are things like Mutex for that
-
durka42
I implemented the parsing part but the trait code is just a huge mass of spaghetti
-
occultus
oh wait, Mutex doesn't work for making a non-Send thing Send
-
Noldorin
occultus, yep
-
occultus
Noldorin: what is the non-Send type?
-
Noldorin
occultus, and Rc
-
ray
shep: thanks for the help, off to bed
-
mib_kmvjos
emilio: I think so?
-
centril
durka42: I'm somewhat happy trait aliases are not stabilized
-
centril
trait Alias = Send + Sync + 'static; is strange to me... this isn't a trait, it is a bound
-
centril
this conflates traits and bounds
-
mib_kmvjos
emilio: wouldn't that mean I could just use one lifetime though? as I understand it, having a notation like Foo<'a> denotes that any references Foo contains live at least as long as 'a, not that their lifetimes are exactly 'a
-
emilio
mib_kmvjos: sure, but then what wouldn't compile is your method, and it makes sense because in the `Owned` case you're not handing out a reference that is guaranteed to live as long as the message, you're handing out an internal reference
-
emilio
mib_kmvjos: So something like that would need `&'message self` to compile, since that's the only thing that guarantees the compiler that it's going to last long enough:
play.rust-lang.org/?gist=0296cf5a3f…5f40e45af1a8e704d48e&version=stable
-
emilio
mib_kmvjos: but of course that's probably not quite usable
-
emilio
-
mib_kmvjos
emilio: right, but that second one's not useful if 'message is 'static then 'b has to also be 'static
-
mib_kmvjos
emilio: and also that one doesn't make sense to me because it's returning references with lifetime 'b, which outlives lifetime 'message, but the values it's referencing may only live 'message, so wouldn't that potentially cause a dangling reference?
-
emilio
mib_kmvjos: err, yeah, you're right
-
Noldorin
so my question is now: why *does* Mutex<T> require T to be Send for the Mutex to be Send?
-
nox
Noldorin: Because sending the mutex is like sending the T inside.
-
Noldorin
nox, give me an example of why this might be a problem
-
nox
Noldorin: Mutex<Rc<T>>
-
occultus
i'm less sure if this fits into rust's model of what Send means, but operations on some data structures are only valid on the thread the data was originally created on
-
nox
Noldorin: Did that help?
-
insaneinside
occultus: that's `Sync`
-
insaneinside
occultus: things that are Sync can be operated on via references from _other_ threads
-
mib_kmvjos
emilio: thanks for the help, I'm gonna keep gnawing at this over the next week or so
-
insaneinside
occultus: i.e. if Thing is Sync, &Thing is Send
-
occultus
insaneinside: i'm not sure if that's the same as what i was referring to
-
occultus
insaneinside: i was thinking of foreign handle values like from Win32
-
Noldorin
nox, that's actually an example of what I don't see is bad
-
insaneinside
occultus, aren't e.g. `WinHnd`s just ints?
-
insaneinside
occultus: (or pointers?)
-
nox
Noldorin: let foo = Rc::new("hello"); let mutex = Mutex::new(foo.clone()); send_mutex_to_other_thread_and_clone_the_Rc_there(mutex);
-
occultus
insaneinside: "just ints" that are not necessarily valid to use from another thread
-
insaneinside
exactly :)
-
nox
Noldorin: It's bad in just the same way that doing it with Rc<T> is bad.
-
insaneinside
I think we're violently agreeing here ;)
-
occultus
insaneinside: so they are not-Send
-
nox
Noldorin: "An example of a non-Send type is the reference-counting pointer rc::Rc. If two threads attempt to clone Rcs that point to the same reference-counted value, they might try to update the reference count at the same time, which is undefined behavior because Rc doesn't use atomic operations."
doc.rust-lang.org/std/marker/trait.Send.html
-
Noldorin
nox, right...
-
Noldorin
makes sense
-
occultus
Noldorin: backtracking a bit, why do want/need to pretend that this non-Send type is Send?
-
Noldorin
nox, what about if any clones done on that new thread are dropped before the Mutex is unlocked. surely that would be safe?
-
Noldorin
occultus, for very pragmatic purposes, kind of boring here :P
-
Noldorin
it's just the type I'm given in a library. need to use it in a multi-threaded way
-
nox
Why aren't you using Arc?
-
insaneinside
^^^^
-
occultus
Arc doesn't make non-Send into Send either
-
occultus
nothing does, and conceptually nothing probably should
-
nox
occultus: I assumed their non-Send type was Rc<T> but that's a wild assumption indeed.
-
ngc0202
is there an accepted style for using comments to section my code?
-
nox
Noldorin: The mutex being locked on that new thread is irrelevant, the other thread is what must not clone the Rc<T>.
-
nox
ngc0202: None, but I sometimes put actual documentation on impl blocks.
-
nox
You can put ## titles with Markdown there and whatnot.
-
Noldorin
nox, let's say that the Rc is only *ever* cloned (and then always dropped) within a lock.
-
ngc0202
I mean stuff like ///// ERROR STUFF /////
-
occultus
Noldorin: that can't be guaranteed
-
Noldorin
occultus, I can guarantee it quite easily from visual inspection of my code, however...
-
nox
Noldorin: I don't see why the lock matters. Why do you need the Rc<T> if you control its entire lifetime?
-
Noldorin
huh?
-
Noldorin
I don't control the Rc<T>
-
Noldorin
it's embedded in a value I'm given
-
Noldorin
from another library
-
occultus
Noldorin: the only way to fix this is to change the library to make the type Send, assuming that it even can be
-
Noldorin
occultus, yeah... guess it just wasn't designed with that in mind
-
nox
Noldorin: What's that type?
-
Noldorin
nox, TestServer in Gotham
-
insaneinside
ngc0202: I do `// ----------------------------------------------------------------` or `// ================================================================` or... you get the picture :)
-
occultus
Noldorin: TestServer is just a wrapper around an Rc
-
insaneinside
ngc0202: for extra fun, remove some of the separators and replace with labels
-
ngc0202
ok, do you use a standard number of dashes?
-
Noldorin
occultus, and a bunch more stuff...
-
Noldorin
but yes