Making a struct Writable

I have a vector struct:


struct Vector(Writable):

  var x: Float64
  var y: Float64

  #...

  fn write_to(self, mut writer: Some[Writer]):
    writer.write("(", self.x, ", ", self.y, ")")

Whether I include the write_to function or not a print(v) always gives the error:

/.../mojo/main.mojo:13:8: error: invalid call to 'print': failed to infer parameter 'Ts', argument type 'Vector' does not conform to trait 'Writable'
  print(u)
  ~~~~~^~~

I’m confused by the Ts parameter reference. Have I misunderstood how Writable works?

TIA!

What version of mojo are you using? I think that specific error message has been completely eliminated - could you give 26.1 or a nightly a try?

Aha! That fixed it. Thanks so much for a really impressive project too.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.