-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
6 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
--- | ||
status: draft | ||
status: approved | ||
flip: 293 | ||
authors: Raymond Zhang ([email protected]) | ||
sponsor: Supun Setunga ([email protected]) | ||
updated: 2024-10-21 | ||
sponsor: Supun Setunga ([email protected]) | ||
updated: 2024-10-30 | ||
--- | ||
|
||
# FLIP 293: StructStringer Interface | ||
|
@@ -12,7 +12,7 @@ updated: 2024-10-21 | |
|
||
This FLIP proposes the addition of a struct interface `StructStringer` to Cadence, which all string-convertible structs will implement. Note that some languages distinguish between a "human-readable representation" and a "debug representation". The purpose of the `StructStringer` interface is to help with providing "human-readable representations" of `AnyStruct` and is separate from the "debug representation" which already exists. | ||
|
||
One goal of this FLIP is to simplify the process for representing `AnyStruct` as a `String`. Secondly, a customizable `toString` will be useful for future string formatting such as string interpolation with this interface. | ||
One goal of this FLIP is to simplify the process for representing `AnyStruct` as a `String`. Secondly, a customizable `toString` will be useful for future string formatting such as string interpolation with this interface. | ||
|
||
## Motivation | ||
|
||
|
@@ -35,7 +35,7 @@ access(all) fun toString(_ value: AnyStruct): String? { | |
... | ||
} | ||
``` | ||
With the proposed addition, the code could be simplified to | ||
With the proposed addition, the code could be simplified to | ||
```cadence | ||
access(all) fun toString(_ value: AnyStruct): String? { | ||
if let stringerValue = value as? {StructStringer} { | ||
|
@@ -54,7 +54,7 @@ This will significantly streamline the process of converting `AnyStruct` values | |
The proposed interface is as follows | ||
|
||
```cadence | ||
access(all) | ||
access(all) | ||
struct interface StructStringer { | ||
access(all) | ||
view fun toString(): String | ||
|