risingwave_common::types::to_text

Trait ToText

source
pub trait ToText {
    // Required methods
    fn write<W: Write>(&self, f: &mut W) -> Result;
    fn write_with_type<W: Write>(&self, _ty: &DataType, f: &mut W) -> Result;

    // Provided methods
    fn to_text_with_type(&self, ty: &DataType) -> String { ... }
    fn to_text(&self) -> String { ... }
}
Expand description

Converts ScalarRef to pgwire “TEXT” format.

§Relationship with casting to varchar

For most types, this is also the implementation for casting to varchar, but there are exceptions. e.g., The TEXT format for boolean is t / f while they cast to varchar true / false.

§Relationship with ToString/Display

For some types, the implementation diverge from Rust’s standard ToString/Display, to match PostgreSQL’s representation.


FIXME: ToText should depend on a lot of other stuff but we have not implemented them yet: timezone, date style, interval style, bytea output, etc

Required Methods§

source

fn write<W: Write>(&self, f: &mut W) -> Result

Write the text to the writer regardless of its data type

See ToText::to_text for more details.

source

fn write_with_type<W: Write>(&self, _ty: &DataType, f: &mut W) -> Result

Write the text to the writer according to its data type

Provided Methods§

source

fn to_text_with_type(&self, ty: &DataType) -> String

Convert to text according to its data type

source

fn to_text(&self) -> String

to_text is a special version of to_text_with_type, it convert the scalar to default type text. E.g. for Int64, it will convert to text as a Int64 type. We should prefer to use to_text_with_type because it’s more clear and readable.

Note: currently the DataType param is actually unnecessary. Previously, Timestamptz is also represented as int64, and we need the data type to distinguish them. Now we have 1-1 mapping, and it happens to be the case that PostgreSQL default ToText format does not need additional metadata like field names contained in DataType.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl ToText for &str

source§

fn write<W: Write>(&self, f: &mut W) -> Result

source§

fn write_with_type<W: Write>(&self, ty: &DataType, f: &mut W) -> Result

source§

impl ToText for &[u8]

source§

fn write<W: Write>(&self, f: &mut W) -> Result

source§

fn write_with_type<W: Write>(&self, ty: &DataType, f: &mut W) -> Result

source§

impl ToText for bool

source§

fn write<W: Write>(&self, f: &mut W) -> Result

source§

fn write_with_type<W: Write>(&self, ty: &DataType, f: &mut W) -> Result

source§

impl ToText for i16

source§

fn write<W: Write>(&self, f: &mut W) -> Result

source§

fn write_with_type<W: Write>(&self, ty: &DataType, f: &mut W) -> Result

source§

impl ToText for i32

source§

fn write<W: Write>(&self, f: &mut W) -> Result

source§

fn write_with_type<W: Write>(&self, ty: &DataType, f: &mut W) -> Result

source§

impl ToText for i64

source§

fn write<W: Write>(&self, f: &mut W) -> Result

source§

fn write_with_type<W: Write>(&self, ty: &DataType, f: &mut W) -> Result

source§

impl ToText for String

source§

fn write<W: Write>(&self, f: &mut W) -> Result

source§

fn write_with_type<W: Write>(&self, ty: &DataType, f: &mut W) -> Result

Implementors§