Comments (8)
Hmm.. I think it should be okay do have:
impl ShallowCopy for Bytes {
unsafe fn shallow_copy(&mut self) -> Self {
Bytes::from_static(self.as_ref())
}
}
Along those lines, I also think it would be good to add
impl<'a, T> ShallowCopy for &'a [T] {
unsafe fn shallow_copy(&mut self) -> Self {
std::slice::from_raw_parts(self.as_ptr(), self.len())
}
}
I'd be happy to take a look at a PR that adds these :)
from left-right.
You want to look into a program that uses those trait implementations? I will try them eventually. What minimal code do you need and why you want to see it?
from left-right.
I'm not sure I understand what you mean? Those trait implementations would need to be added to evmap
itself for you to be able to rely on them in an external crate.
from left-right.
A really? Ok I was under the impression, that the user software implement those traits for Bytes in their code. Because you can not implement ShallowCopy for all types in evmap. Its the users duty to implement it on the types they use. Not?
from left-right.
Ah, no, we're limited here by Rust's orphan rule:
One restriction to note with trait implementations is that we can implement a
trait on a type only if either the trait or the type is local to our crate.
For example, we can implement standard library traits likeDisplay
on a
custom type likeTweet
as part of our aggregator crate functionality,
because the typeTweet
is local to our aggregator crate. We can also
implementSummary
onVec<T>
in our aggregator crate, because the trait
Summary
is local to our aggregator crate.But we can’t implement external traits on external types. For example, we
can’t implement theDisplay
trait onVec<T>
within our aggregator crate,
becauseDisplay
andVec<T>
are defined in the standard library and aren’t
local to our aggregator crate. This restriction is part of a property of
programs called coherence, and more specifically the orphan rule, so
named because the parent type is not present. This rule ensures that other
people’s code can’t break your code and vice versa. Without the rule, two
crates could implement the same trait for the same type, and Rust wouldn’t
know which implementation to use.
In other words, since evmap
defines the ShallowCopy
trait, either the byte
crate would have to implement ShallowCopy
for Bytes
(which seems unlikely) or that implementation has to exist inside of evmap
. Since byte::Bytes
is so common, I think I'd be okay with including that impl directly here :)
from left-right.
I see. So I guess I have to wait for your update of evmap then, or use some other type until then.
from left-right.
Or you can submit a pull request yourself that makes the necessary changes (adding a dependency on byte
, the impl
s above, and tests with the corresponding types) which I could then review and merge :)
from left-right.
Fixed in #30!
from left-right.
Related Issues (20)
- Support for no_std? HOT 5
- i saw the presentation, will it take a lot of CPU like spinlock while write is waiting? HOT 1
- Why you dont use Crossbeam Epoch?? i have question about this please help HOT 1
- Recoverable errors from fallible operation HOT 5
- Memory bloat when using with async runtime HOT 2
- Possible to shallowcopy a HashMap HOT 1
- #[derive(ShallowCopy)] has prohibitive "T: ShallowCopy" bound HOT 4
- Thread Safety Error on ReadHandler HOT 3
- Why not make `map_ref` of `ReadGuard` public? HOT 1
- Recreating WriteHandle after its dropped HOT 2
- RFC: Hash and Eq requirement for values HOT 4
- Replace Clone bound with Freeze HOT 4
- Possible UB from Box<T> aliasing HOT 7
- data races due to incorrect `Send + Sync` bounds HOT 3
- Relaxation of epoch invariant HOT 2
- rollback HOT 5
- Switch oplog to VecDeque HOT 1
- A potential alternative to epochs, if it works HOT 1
- can DropBehavior have an associated constant instead of a function HOT 11
- Is there a way to get the backing data structure out? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from left-right.