missing/confusing documentation of behavior of str::{floor_char_boundary, ceil_char_boundary} when index > len

Aperta Adatta ai principianti
#165,295 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
70/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
documentation

Direzione di ricerca

Il lavoro riguarda i commenti di documentazione di str::floor_char_boundary e str::ceil_char_boundary nel codice sorgente della libreria standard. Trova entrambi i metodi e leggi il commento esistente su ceil_char_boundary, che dice che il risultato è la lunghezza della stringa quando l'indice supera la fine, ma definisce quel valore «non inferiore all'indice», il che è una contraddizione. Aggiungi una frase a floor_char_boundary che descriva lo stesso comportamento fuori intervallo e riformula la nota di ceil_char_boundary. È completato quando entrambe le documentazioni descrivono il comportamento di clamping senza contraddizioni e i test della documentazione continuano a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A-docs needs-triage
Location (URL)

https://doc.rust-lang.org/1.99.1/std/primitive.str.html#method.floor_char_boundary
https://doc.rust-lang.org/1.99.1/std/primitive.str.html#method.ceil_char_boundary

Summary

The documentation for str::floor_char_boundary doesn't say what happens if the requested index is greater than the string length: will it panic? return the input value? clamp to the string length?

It appears the result will always be clamped to a valid byte index, i.e. if the input is past the end, then the return value will be the string length. This means that truncating a string with &s[..s.floor_char_boundary(i)] will do the expected thing (and never panic).

Additionally, str::ceil_char_boundary does document its behavior in this case, but that documentation somewhat contradicts itself:

/// Finds the closest `x` not below `index` where [`is_char_boundary(x)`] is `true`.
///
/// If `index` is greater than the length of the string, this returns the length of the string.

This is confusing because "the length of the string" is a possible return value that could be below index. Perhaps there's a better way to write that?

Lingua principale
Rust
Stelle
121k
Fork
18k
Merge medio
2g 17h
PR unite (30g)
511

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/rust

Tutte le issue di rust-lang/rust

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.