Comments (1)
This would be very useful for const fn
s that sometimes need to handle runtime data too, such as a const fn
method that needs to use a Cow<'static, [T]>
field.
For example:
struct Foo(Cow<'static, [u32]>);
impl Foo {
// Initialize with heap-allocated data at runtime.
fn heap(data: Vec<u32>) -> Self {
Foo(Cow::Owned(data))
}
// Initialize with static data at compile-time.
const fn static(data: &'static [u32]) -> Self {
Foo(Cow::Borrowed(data))
}
// Access the data, possibly at compile-time, possibly at runtime.
const fn data(&self) -> &[u32] {
match self.0 {
Cow::Borrowed(slice) => slice,
Cow::Owned(vec) => vec.as_slice(),
}
}
}
from rust.
Related Issues (20)
- ICE: `None` in compiler/rustc_middle/src/ty/sty.rs HOT 2
- Specific inline ASM in specific project generates invalid ASM HOT 3
- multiple platforms incorrectly impl `thread::sleep` with `Duration::as_micros` HOT 4
- ICE: `Encountered error SignatureMismatch`
- ICE: no `enclosing_body_owner` for hir_id HOT 1
- ICE: `associated type missing default`
- ICE: invalid pointer unsizing &dyn Foo -> [i32]
- using extern "x86-interrupt" + #[naked] + kernel address sanitizer crashes compiler HOT 4
- Compiler panics when i run cargo check HOT 3
- const_heap feature can be used to leak mutable memory into final value of constant
- `-Zthreads` is slower the more cores I add HOT 1
- `std::fs::canonicalize` failed to process path mounted with cppcryptfs/dokan under windows HOT 1
- rustc_driver: There is no explanation of when the IRs (HIR, THIR, MIR) become available.
- Delay def creation for expression-like nodes HOT 1
- Refining generic bounds in trait method HOT 4
- Unsized parameters are not flagged in trait definitions
- E0382: Add help for fixing a partially moved struct by manual assignment
- `single_use_lifetimes`: false positive (suggests unstable anonymous lifetimes in `impl Trait`)
- argon2rs is broken in nightly in `LoweringContext>::create_def.cold` HOT 1
- ICE: field should be captured by immutable ref if we have an `Fn` instance
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 rust.