Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cannot create aSnippet without know whether annotation or patch #300

Open
Labels
C-enhancementCategory: enhancementM-breaking-changeMeta: Implementing or merging this will introduce a breaking change
@epage

Description

@epage

I have code like the following

fntypo_to_group<'t>(msg:&'tTypo<'t>) ->Group<'t>{let title =match&msg.corrections{        typos::Status::Valid =>unimplemented!("never valid words to report"),        typos::Status::Invalid =>{format!("`{}` is disallowed", msg.typo,)}        typos::Status::Corrections(corrections) =>{format!("`{}` should be {}",                msg.typo,                itertools::join(corrections.iter().map(|s| format!("`{s}`")),", "))}};let group =Group::with_title(Level::ERROR.primary_title(Cow::Owned(title)));let group =match&msg.context{Some(Context::File(context)) =>{let path = context.path.as_os_str().to_string_lossy();let line =String::from_utf8_lossy(msg.buffer.as_ref());let snippet =Snippet::source(line).path(path).line_start(context.line_num);append_corrections(msg,0, snippet, group)}Some(Context::Path(context)) =>{let path = context.path.parent().unwrap_or(std::path::Path::new(".")).join("");let path = path.as_os_str().to_string_lossy();let line = context.path.as_os_str().to_string_lossy();let snippet =Snippet::source(line);append_corrections(msg, path.len(), snippet, group)}Some(_) |None => group,};    group}fnappend_corrections<'t>(msg:&'tTypo<'t>,offset:usize,snippet:Snippet<'t,Annotation<'t>>,group:Group<'t>,) ->Group<'t>{let span_start = msg.byte_offset + offset;let span_end = span_start + msg.typo.len();let span = span_start..span_end;match&msg.corrections{        typos::Status::Valid =>unimplemented!("never valid words to report"),        typos::Status::Invalid =>{let snippet = snippet.annotation(AnnotationKind::Primary.span(span));            group.element(snippet)}        typos::Status::Corrections(corrections) =>{let snippet = snippet.annotation(AnnotationKind::Primary.span(span));            group.element(snippet)}}}

The problem is that I want to make theCorrections variant inappend_corrections usePatch but can't because the passed insnippet has to have one specific type.

One option is for us to createSnippets withT = () and thenannotation can convert it toT= Annotation andpatch toT= Patch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: enhancementM-breaking-changeMeta: Implementing or merging this will introduce a breaking change

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp