`slice-dst`: Provide example for custom 'slices' using `SliceWithHeader`
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
- Tipo di issue
- Documentazione
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- rust
- Ambito
- documentation
Direzione di ricerca
Inizia dal tipo SliceWithHeader e dall'esempio personalizzato MyString/MyStr nell'issue; non è identificato alcun file o test. Stabilisci i requisiti di sicurezza per la conversione di riferimento proposta, quindi documenta un esempio completo di slice personalizzato e il relativo comportamento previsto di Borrow/ToOwned.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Thank you for this awesome crate. I always respect when people dive into the unsafe world of Rust.
I'd like to use the slice-dst crate to build something similar to String and str. Let's assume:
struct MyString(Box<SliceWithHeader<Info, u8>>);
To mimicry str I want to implement Borrow<MyStr> for MyString and ToOwned for MyStr (type Owned = MyString). However, I have a problem defining MyStr. I could use a type alias:
type MyStr = SliceWithHeader<Info, u8>;
But this is inconvenient and won't allow some custom impl MyStr. What I would like is to use is a new-type-pattern. But this makes it difficult implementing Borrow:
struct MyStr(SliceWithHeader<Info, u8>);
impl Borrow<MyStr> for MyString {
fn borrow(&self) -> &MyStr {
&*self.0 // <-- requires some cast/convertion/idk
}
}
Would it be safe to simple cast the reference from the Box within MyString to a &MyStr or would this be undefined behavior?
- Lingua principale
- Rust
- Stelle
- 137
- Fork
- 15
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di CAD97/pointer-utils
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
CAD97/pointer-utils#88 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
CAD97/pointer-utils#87 · 3 reazioni ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
CAD97/pointer-utils#85 · 3 commenti ·
-
FatErasedPtr Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
CAD97/pointer-utils#84 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
CAD97/pointer-utils#75 · 3 commenti ·
Tutte le issue di CAD97/pointer-utils
Issue simili
-
bug github_actions
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
registrystack/registry-stack#1393 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
longbridge/gpui-kit#3223 ·
-
bug engine
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
rocky-data/rocky#2181 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
oasisprotocol/oasis-sdk#2523 ·
-
[indexer] [QA] Add a focused test for the new NonRetryableError / assertSocketAlive() behavior. Apertabot:ai-assisted component:indexer QA-roadmap status:untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
midnightntwrk/midnight-indexer#1557 ·