pub struct RandomLocator<'a> {
    pub source: &'a str,
    /* private fields */
}
Expand description

Converts source code byte-offset to Python convention line and column numbers.

Fields§

§source: &'a str

Implementations§

source§

impl<'a> RandomLocator<'a>

source

pub fn new(source: &'a str) -> RandomLocator<'a>

source

pub fn to_source_code(&self) -> SourceCode<'_, '_>

source

pub fn locate(&mut self, offset: TextSize) -> SourceLocation

source

pub fn locate_error<T, U>(&mut self, base: BaseError<T>) -> LocatedError<U>
where T: Into<U>,

Trait Implementations§

source§

impl Fold<TextRange> for RandomLocator<'_>

§

type TargetU = SourceRange

§

type Error = Infallible

§

type UserContext = SourceLocation

source§

fn will_map_user(&mut self, user: &TextRange) -> Self::UserContext

source§

fn map_user( &mut self, user: TextRange, start: Self::UserContext ) -> Result<Self::TargetU, Self::Error>

source§

fn will_map_user_cfg( &mut self, _user: &EmptyRange<U> ) -> EmptyRange<Self::TargetU>

source§

fn map_user_cfg( &mut self, _user: EmptyRange<U>, _context: EmptyRange<Self::TargetU> ) -> Result<EmptyRange<Self::TargetU>, Self::Error>

source§

fn fold<X: Foldable<U, Self::TargetU>>( &mut self, node: X ) -> Result<X::Mapped, Self::Error>

source§

fn fold_mod(&mut self, node: Mod<U>) -> Result<Mod<Self::TargetU>, Self::Error>

source§

fn fold_mod_module( &mut self, node: ModModule<U> ) -> Result<ModModule<Self::TargetU>, Self::Error>

source§

fn fold_mod_interactive( &mut self, node: ModInteractive<U> ) -> Result<ModInteractive<Self::TargetU>, Self::Error>

source§

fn fold_mod_expression( &mut self, node: ModExpression<U> ) -> Result<ModExpression<Self::TargetU>, Self::Error>

source§

fn fold_mod_function_type( &mut self, node: ModFunctionType<U> ) -> Result<ModFunctionType<Self::TargetU>, Self::Error>

source§

fn fold_stmt( &mut self, node: Stmt<U> ) -> Result<Stmt<Self::TargetU>, Self::Error>

source§

fn fold_stmt_function_def( &mut self, node: StmtFunctionDef<U> ) -> Result<StmtFunctionDef<Self::TargetU>, Self::Error>

source§

fn fold_stmt_async_function_def( &mut self, node: StmtAsyncFunctionDef<U> ) -> Result<StmtAsyncFunctionDef<Self::TargetU>, Self::Error>

source§

fn fold_stmt_class_def( &mut self, node: StmtClassDef<U> ) -> Result<StmtClassDef<Self::TargetU>, Self::Error>

source§

fn fold_stmt_return( &mut self, node: StmtReturn<U> ) -> Result<StmtReturn<Self::TargetU>, Self::Error>

source§

fn fold_stmt_delete( &mut self, node: StmtDelete<U> ) -> Result<StmtDelete<Self::TargetU>, Self::Error>

source§

fn fold_stmt_assign( &mut self, node: StmtAssign<U> ) -> Result<StmtAssign<Self::TargetU>, Self::Error>

source§

fn fold_stmt_type_alias( &mut self, node: StmtTypeAlias<U> ) -> Result<StmtTypeAlias<Self::TargetU>, Self::Error>

source§

fn fold_stmt_aug_assign( &mut self, node: StmtAugAssign<U> ) -> Result<StmtAugAssign<Self::TargetU>, Self::Error>

source§

fn fold_stmt_ann_assign( &mut self, node: StmtAnnAssign<U> ) -> Result<StmtAnnAssign<Self::TargetU>, Self::Error>

source§

fn fold_stmt_for( &mut self, node: StmtFor<U> ) -> Result<StmtFor<Self::TargetU>, Self::Error>

source§

fn fold_stmt_async_for( &mut self, node: StmtAsyncFor<U> ) -> Result<StmtAsyncFor<Self::TargetU>, Self::Error>

source§

fn fold_stmt_while( &mut self, node: StmtWhile<U> ) -> Result<StmtWhile<Self::TargetU>, Self::Error>

source§

fn fold_stmt_if( &mut self, node: StmtIf<U> ) -> Result<StmtIf<Self::TargetU>, Self::Error>

source§

fn fold_stmt_with( &mut self, node: StmtWith<U> ) -> Result<StmtWith<Self::TargetU>, Self::Error>

source§

fn fold_stmt_async_with( &mut self, node: StmtAsyncWith<U> ) -> Result<StmtAsyncWith<Self::TargetU>, Self::Error>

source§

fn fold_stmt_match( &mut self, node: StmtMatch<U> ) -> Result<StmtMatch<Self::TargetU>, Self::Error>

source§

fn fold_stmt_raise( &mut self, node: StmtRaise<U> ) -> Result<StmtRaise<Self::TargetU>, Self::Error>

source§

fn fold_stmt_try( &mut self, node: StmtTry<U> ) -> Result<StmtTry<Self::TargetU>, Self::Error>

source§

fn fold_stmt_try_star( &mut self, node: StmtTryStar<U> ) -> Result<StmtTryStar<Self::TargetU>, Self::Error>

source§

fn fold_stmt_assert( &mut self, node: StmtAssert<U> ) -> Result<StmtAssert<Self::TargetU>, Self::Error>

source§

fn fold_stmt_import( &mut self, node: StmtImport<U> ) -> Result<StmtImport<Self::TargetU>, Self::Error>

source§

fn fold_stmt_import_from( &mut self, node: StmtImportFrom<U> ) -> Result<StmtImportFrom<Self::TargetU>, Self::Error>

source§

fn fold_stmt_global( &mut self, node: StmtGlobal<U> ) -> Result<StmtGlobal<Self::TargetU>, Self::Error>

source§

fn fold_stmt_nonlocal( &mut self, node: StmtNonlocal<U> ) -> Result<StmtNonlocal<Self::TargetU>, Self::Error>

source§

fn fold_stmt_expr( &mut self, node: StmtExpr<U> ) -> Result<StmtExpr<Self::TargetU>, Self::Error>

source§

fn fold_stmt_pass( &mut self, node: StmtPass<U> ) -> Result<StmtPass<Self::TargetU>, Self::Error>

source§

fn fold_stmt_break( &mut self, node: StmtBreak<U> ) -> Result<StmtBreak<Self::TargetU>, Self::Error>

source§

fn fold_stmt_continue( &mut self, node: StmtContinue<U> ) -> Result<StmtContinue<Self::TargetU>, Self::Error>

source§

fn fold_expr( &mut self, node: Expr<U> ) -> Result<Expr<Self::TargetU>, Self::Error>

source§

fn fold_expr_bool_op( &mut self, node: ExprBoolOp<U> ) -> Result<ExprBoolOp<Self::TargetU>, Self::Error>

source§

fn fold_expr_named_expr( &mut self, node: ExprNamedExpr<U> ) -> Result<ExprNamedExpr<Self::TargetU>, Self::Error>

source§

fn fold_expr_bin_op( &mut self, node: ExprBinOp<U> ) -> Result<ExprBinOp<Self::TargetU>, Self::Error>

source§

fn fold_expr_unary_op( &mut self, node: ExprUnaryOp<U> ) -> Result<ExprUnaryOp<Self::TargetU>, Self::Error>

source§

fn fold_expr_lambda( &mut self, node: ExprLambda<U> ) -> Result<ExprLambda<Self::TargetU>, Self::Error>

source§

fn fold_expr_if_exp( &mut self, node: ExprIfExp<U> ) -> Result<ExprIfExp<Self::TargetU>, Self::Error>

source§

fn fold_expr_dict( &mut self, node: ExprDict<U> ) -> Result<ExprDict<Self::TargetU>, Self::Error>

source§

fn fold_expr_set( &mut self, node: ExprSet<U> ) -> Result<ExprSet<Self::TargetU>, Self::Error>

source§

fn fold_expr_list_comp( &mut self, node: ExprListComp<U> ) -> Result<ExprListComp<Self::TargetU>, Self::Error>

source§

fn fold_expr_set_comp( &mut self, node: ExprSetComp<U> ) -> Result<ExprSetComp<Self::TargetU>, Self::Error>

source§

fn fold_expr_dict_comp( &mut self, node: ExprDictComp<U> ) -> Result<ExprDictComp<Self::TargetU>, Self::Error>

source§

fn fold_expr_generator_exp( &mut self, node: ExprGeneratorExp<U> ) -> Result<ExprGeneratorExp<Self::TargetU>, Self::Error>

source§

fn fold_expr_await( &mut self, node: ExprAwait<U> ) -> Result<ExprAwait<Self::TargetU>, Self::Error>

source§

fn fold_expr_yield( &mut self, node: ExprYield<U> ) -> Result<ExprYield<Self::TargetU>, Self::Error>

source§

fn fold_expr_yield_from( &mut self, node: ExprYieldFrom<U> ) -> Result<ExprYieldFrom<Self::TargetU>, Self::Error>

source§

fn fold_expr_compare( &mut self, node: ExprCompare<U> ) -> Result<ExprCompare<Self::TargetU>, Self::Error>

source§

fn fold_expr_call( &mut self, node: ExprCall<U> ) -> Result<ExprCall<Self::TargetU>, Self::Error>

source§

fn fold_expr_formatted_value( &mut self, node: ExprFormattedValue<U> ) -> Result<ExprFormattedValue<Self::TargetU>, Self::Error>

source§

fn fold_expr_joined_str( &mut self, node: ExprJoinedStr<U> ) -> Result<ExprJoinedStr<Self::TargetU>, Self::Error>

source§

fn fold_expr_constant( &mut self, node: ExprConstant<U> ) -> Result<ExprConstant<Self::TargetU>, Self::Error>

source§

fn fold_expr_attribute( &mut self, node: ExprAttribute<U> ) -> Result<ExprAttribute<Self::TargetU>, Self::Error>

source§

fn fold_expr_subscript( &mut self, node: ExprSubscript<U> ) -> Result<ExprSubscript<Self::TargetU>, Self::Error>

source§

fn fold_expr_starred( &mut self, node: ExprStarred<U> ) -> Result<ExprStarred<Self::TargetU>, Self::Error>

source§

fn fold_expr_name( &mut self, node: ExprName<U> ) -> Result<ExprName<Self::TargetU>, Self::Error>

source§

fn fold_expr_list( &mut self, node: ExprList<U> ) -> Result<ExprList<Self::TargetU>, Self::Error>

source§

fn fold_expr_tuple( &mut self, node: ExprTuple<U> ) -> Result<ExprTuple<Self::TargetU>, Self::Error>

source§

fn fold_expr_slice( &mut self, node: ExprSlice<U> ) -> Result<ExprSlice<Self::TargetU>, Self::Error>

source§

fn fold_expr_context( &mut self, node: ExprContext ) -> Result<ExprContext, Self::Error>

source§

fn fold_boolop(&mut self, node: BoolOp) -> Result<BoolOp, Self::Error>

source§

fn fold_operator(&mut self, node: Operator) -> Result<Operator, Self::Error>

source§

fn fold_unaryop(&mut self, node: UnaryOp) -> Result<UnaryOp, Self::Error>

source§

fn fold_cmpop(&mut self, node: CmpOp) -> Result<CmpOp, Self::Error>

source§

fn fold_comprehension( &mut self, node: Comprehension<U> ) -> Result<Comprehension<Self::TargetU>, Self::Error>

source§

fn fold_excepthandler( &mut self, node: ExceptHandler<U> ) -> Result<ExceptHandler<Self::TargetU>, Self::Error>

source§

fn fold_excepthandler_except_handler( &mut self, node: ExceptHandlerExceptHandler<U> ) -> Result<ExceptHandlerExceptHandler<Self::TargetU>, Self::Error>

source§

fn fold_arguments( &mut self, node: Arguments<U> ) -> Result<Arguments<Self::TargetU>, Self::Error>

source§

fn fold_arg(&mut self, node: Arg<U>) -> Result<Arg<Self::TargetU>, Self::Error>

source§

fn fold_keyword( &mut self, node: Keyword<U> ) -> Result<Keyword<Self::TargetU>, Self::Error>

source§

fn fold_alias( &mut self, node: Alias<U> ) -> Result<Alias<Self::TargetU>, Self::Error>

source§

fn fold_withitem( &mut self, node: WithItem<U> ) -> Result<WithItem<Self::TargetU>, Self::Error>

source§

fn fold_match_case( &mut self, node: MatchCase<U> ) -> Result<MatchCase<Self::TargetU>, Self::Error>

source§

fn fold_pattern( &mut self, node: Pattern<U> ) -> Result<Pattern<Self::TargetU>, Self::Error>

source§

fn fold_pattern_match_value( &mut self, node: PatternMatchValue<U> ) -> Result<PatternMatchValue<Self::TargetU>, Self::Error>

source§

fn fold_pattern_match_singleton( &mut self, node: PatternMatchSingleton<U> ) -> Result<PatternMatchSingleton<Self::TargetU>, Self::Error>

source§

fn fold_pattern_match_sequence( &mut self, node: PatternMatchSequence<U> ) -> Result<PatternMatchSequence<Self::TargetU>, Self::Error>

source§

fn fold_pattern_match_mapping( &mut self, node: PatternMatchMapping<U> ) -> Result<PatternMatchMapping<Self::TargetU>, Self::Error>

source§

fn fold_pattern_match_class( &mut self, node: PatternMatchClass<U> ) -> Result<PatternMatchClass<Self::TargetU>, Self::Error>

source§

fn fold_pattern_match_star( &mut self, node: PatternMatchStar<U> ) -> Result<PatternMatchStar<Self::TargetU>, Self::Error>

source§

fn fold_pattern_match_as( &mut self, node: PatternMatchAs<U> ) -> Result<PatternMatchAs<Self::TargetU>, Self::Error>

source§

fn fold_pattern_match_or( &mut self, node: PatternMatchOr<U> ) -> Result<PatternMatchOr<Self::TargetU>, Self::Error>

source§

fn fold_type_ignore( &mut self, node: TypeIgnore<U> ) -> Result<TypeIgnore<Self::TargetU>, Self::Error>

source§

fn fold_type_ignore_type_ignore( &mut self, node: TypeIgnoreTypeIgnore<U> ) -> Result<TypeIgnoreTypeIgnore<Self::TargetU>, Self::Error>

source§

fn fold_type_param( &mut self, node: TypeParam<U> ) -> Result<TypeParam<Self::TargetU>, Self::Error>

source§

fn fold_type_param_type_var( &mut self, node: TypeParamTypeVar<U> ) -> Result<TypeParamTypeVar<Self::TargetU>, Self::Error>

source§

fn fold_type_param_param_spec( &mut self, node: TypeParamParamSpec<U> ) -> Result<TypeParamParamSpec<Self::TargetU>, Self::Error>

source§

fn fold_type_param_type_var_tuple( &mut self, node: TypeParamTypeVarTuple<U> ) -> Result<TypeParamTypeVarTuple<Self::TargetU>, Self::Error>

source§

fn fold_arg_with_default( &mut self, node: ArgWithDefault<U> ) -> Result<ArgWithDefault<Self::TargetU>, Self::Error>

Auto Trait Implementations§

§

impl<'a> Freeze for RandomLocator<'a>

§

impl<'a> RefUnwindSafe for RandomLocator<'a>

§

impl<'a> Send for RandomLocator<'a>

§

impl<'a> Sync for RandomLocator<'a>

§

impl<'a> Unpin for RandomLocator<'a>

§

impl<'a> UnwindSafe for RandomLocator<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> ExactFrom<T> for U
where U: TryFrom<T>,

source§

fn exact_from(value: T) -> U

source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

source§

fn exact_into(self) -> U

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

source§

fn wrapping_into(self) -> U