Skip to main content

Questions tagged [coercion]

Coercion, type conversion and typecasting are different ways of, implicitly or explicitly, changing an entity of one data type into another.

-1 votes
1 answer
133 views

What does Rust error "you could box the found value and coerce it to the trait object" mean?

What does this error mean? Reproduction error[E0308]: mismatched types --> src/main.rs:50:35 | 50 | PaymentType::InvoiceIn => InvoiceIn { | ___________________________________^...
Fred Hors's user avatar
  • 3,805
0 votes
0 answers
25 views

Understanding coercion of Box<Trait> to Box<dyn Trait> [duplicate]

I am just starting to learn Rust and if there is one topic that confused me it's coercion when it comes to trait objects. trait Trait { fn test(&self) -> (); } struct A{ num: u32 } ...
GamefanA's user avatar
  • 1,643
3 votes
1 answer
34 views

How get an immutable Pin from a mutable Pin?

How to apply deref coercion from &mut to & for references that are wrapped inside Pin<>? That is, how to borrow Pin<&mut _> as Pin<&_>? use std::pin::{Pin, pin}; fn ...
tolvanea's user avatar
0 votes
1 answer
50 views

How does Dereferencing with Traits and Trait functions with Slices and Arrays work

(I am new to rust and trying to write a little card game as an exercise and I might not have grasped some things correctly. I am trying to break down my problem/confusion as much as I can.) I want to ...
Don's user avatar
  • 227
0 votes
2 answers
34 views

In R, how do you change the class of data in a matrix?

Say you have a matrix of logical values of size 6x4: set.seed(4) mat <- matrix(sample(c(T, F), 24, replace = T), ncol = 4) mat # [,1] [,2] [,3] [,4] # [1,] FALSE TRUE FALSE FALSE # [2,] ...
Dan Lewer's user avatar
  • 944
4 votes
2 answers
71 views

Admissble type role overrides

In GHC Haskell, Map k v has a type role declaration for k to be nominal. This is because the user can otherwise coerce k to another type with the same representation but different Ord instance, ...
Trebor's user avatar
  • 430
0 votes
0 answers
45 views

Equivalent Casting of JPEG to Data, but with .mov files in Swift

I have some code that works fine, using Amplify to push and pull images from an AWS-S3 bucket. let uploadTask = Amplify.Storage.uploadData(key: imageKey, data: srcData, options: nil) Task { ...
Dan Donaldson's user avatar
0 votes
0 answers
275 views

'length(x) = 2 > 1' in coercion to 'logical(1)'

I am getting above error whenever I am passing more than two conditions in if statement. I also tried 'all' instead of if statement but it also did not work. Error is : Warning in distType == "...
kumari sinam's user avatar
0 votes
0 answers
26 views

Is there a way to get the data from an Applescript image (AXImage), perhaps using Applescript/Obj-C?

Hi there — I’m writing an Applescript that uses System Events to get an image: tell application “System Events” tell process “appName” tell window 1 set theImage to image 1 ...
Michael Norris's user avatar
0 votes
0 answers
61 views

Is there a Rust signature signaling that any type that coerces into T would be allowed? [duplicate]

So I just started learning about Rust and the Implicit Deref Coercion. A "problem" I now often tumble over, is that this automatic deref does not work inside of other types, e.g. as Item ...
David S.'s user avatar
  • 313
2 votes
0 answers
134 views

Specify in Rust that a generic type supports coercion to a primitive type

In Rust, I have several different enums that are all #[repr(u32)], meaning I can use as to cast them to a u32: #[repr(u32)] enum Foo {A, B, C} fn f(foo: Foo) { dbg!(foo as u32); } Now I want to ...
Michael Mrozek's user avatar
0 votes
1 answer
264 views

ToPrimitive VS OrdinaryToPrimitive

I am reading the Book, YDKJS by Kyle Simpson, topic Coercion. While looking at the specs I found that ToPrimitive calls OrdinaryToPrimitive conditionally. I read in a blog that: JavaScript view ...
Sadiq's user avatar
  • 838
2 votes
1 answer
132 views

Why do I need to use `&` to trigger deref coercion in rust?

From The Rust Programming Language book: Deref coercion converts a reference to a type that implements the Deref trait into reference to another type Questions in code snippet below: Why & is ...
Ievgen's user avatar
  • 2,079
3 votes
1 answer
272 views

Why do I need to implement `From` for both a value and a reference? Shouldn't methods be automatically dereferenced or borrowed?

The behaviour of a Rust method call is described in The Rust Reference. It states that "when looking up a method call, the receiver may be automatically dereferenced or borrowed in order to call ...
scottwillmoore's user avatar
0 votes
0 answers
167 views

TS: Conditional property based on the value of a generic

Here I have a stripped down code snippet to demonstrate the sort of thing I'm trying to achieve: interface A<RequiresB extends boolean = true> { alwaysRequired: string b: RequiresB extends ...
SY6Dave's user avatar
  • 49

15 30 50 per page
1
2 3 4 5
27